refactor(social): drop redundant \$account->refresh() after CV refresh

Every refresh*Token method inside ConnectionVerifier already finishes
with \$account->update(...) (mutates the model) + \$account->refresh()
(reloads from DB to pick up sibling updates like LinkedInTokenSynchronizer).
The lock-contention branch in refreshToken() also calls \$account->refresh()
before returning.

So a second \$account->refresh() in the caller was always a redundant
SELECT — no scenario where it actually pulled a different value than
what CV already left in memory. Removed from all 15 call sites, plus
fixed the duplicated "Mastodon tokens don't expire" comment.
This commit is contained in:
Paulo Castellano 2026-05-19 09:52:49 -03:00
parent a42962c0ca
commit 6c6078fa6a
18 changed files with 2 additions and 29 deletions

View file

@ -30,7 +30,6 @@ public function publish(PostPlatform $postPlatform): array
// Refresh token if needed
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$medias = $postPlatform->post->mediaItems;

View file

@ -99,9 +99,8 @@ public function refreshToken(SocialAccount $account): void
Platform::Pinterest => $this->refreshPinterestToken($account),
Platform::Threads => $this->refreshThreadsToken($account),
Platform::Instagram => $this->refreshInstagramToken($account),
// InstagramFacebook uses page tokens that don't expire (like Facebook)
// Mastodon tokens don't expire
// Mastodon tokens don't expire
// Facebook / InstagramFacebook use Page tokens that don't expire.
// Mastodon tokens don't expire either.
default => null,
};
} finally {

View file

@ -46,7 +46,6 @@ public function fetchPostMetrics(PostPlatform $postPlatform): array
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;
@ -90,7 +89,6 @@ private function fetchMetricsFromApi(SocialAccount $account, CarbonInterface $si
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;

View file

@ -31,7 +31,6 @@ public function publish(PostPlatform $postPlatform): array
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$instagramId = $account->platform_user_id;

View file

@ -52,7 +52,6 @@ public function fetchPostMetrics(PostPlatform $postPlatform): array
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
// platform_post_id is the share URN (e.g., "urn:li:share:12345").
@ -82,7 +81,6 @@ private function fetchMetricsFromApi(SocialAccount $account, CarbonInterface $si
{
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;

View file

@ -47,7 +47,6 @@ public function publish(PostPlatform $postPlatform): array
if ($this->account->is_token_expired || $this->account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($this->account);
$this->account->refresh();
}
$this->accessToken = $this->account->access_token;
@ -82,7 +81,6 @@ private function retryWithRefresh(PostPlatform $postPlatform, ?string $content,
try {
app(ConnectionVerifier::class)->refreshToken($this->account);
$this->account->refresh();
$this->accessToken = $this->account->access_token;
$organizationId = $this->account->meta['organization_id'] ?? null;

View file

@ -47,7 +47,6 @@ public function publish(PostPlatform $postPlatform): array
if ($this->account->is_token_expired || $this->account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($this->account);
$this->account->refresh();
}
$this->accessToken = $this->account->access_token;
@ -76,7 +75,6 @@ private function retryWithRefresh(PostPlatform $postPlatform, ?string $content,
try {
app(ConnectionVerifier::class)->refreshToken($this->account);
$this->account->refresh();
$this->accessToken = $this->account->access_token;
$personUrn = "urn:li:person:{$this->account->platform_user_id}";

View file

@ -48,7 +48,6 @@ public function fetchPostMetrics(PostPlatform $postPlatform): array
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$start = now()->subDays(90)->format('Y-m-d');
@ -93,7 +92,6 @@ private function fetchMetricsFromApi(SocialAccount $account, CarbonInterface $si
{
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;

View file

@ -35,7 +35,6 @@ public function publish(PostPlatform $postPlatform): array
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$content = $postPlatform->post->content ? app(ContentSanitizer::class)->sanitize($postPlatform->post->content, $postPlatform->platform) : null;
@ -407,7 +406,6 @@ public function getBoards(SocialAccount $account): array
{
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$response = $this->socialHttp()->withToken($account->access_token)

View file

@ -48,7 +48,6 @@ public function fetchPostMetrics(PostPlatform $postPlatform): array
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$response = $this->socialHttp()
@ -80,7 +79,6 @@ private function fetchMetricsFromApi(SocialAccount $account, CarbonInterface $si
{
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;

View file

@ -31,7 +31,6 @@ public function publish(PostPlatform $postPlatform): array
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$userId = $account->platform_user_id;

View file

@ -37,7 +37,6 @@ private function fetchMetricsFromApi(SocialAccount $account): array
{
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;

View file

@ -60,7 +60,6 @@ private function fetchFresh(SocialAccount $account): array
{
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;

View file

@ -37,7 +37,6 @@ public function publish(PostPlatform $postPlatform): array
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;

View file

@ -48,7 +48,6 @@ private function fetchMetricsFromApi(SocialAccount $account, CarbonInterface $si
{
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;
@ -164,7 +163,6 @@ public function fetchPostMetrics(PostPlatform $postPlatform): array
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;

View file

@ -38,7 +38,6 @@ public function publish(PostPlatform $postPlatform): array
// Refresh token if expired or expiring soon
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;

View file

@ -48,7 +48,6 @@ public function fetchPostMetrics(PostPlatform $postPlatform): array
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;
@ -100,7 +99,6 @@ private function fetchMetricsFromApi(SocialAccount $account, CarbonInterface $si
{
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$this->accessToken = $account->access_token;

View file

@ -35,7 +35,6 @@ public function publish(PostPlatform $postPlatform): array
if ($account->is_token_expired || $account->is_token_expiring_soon) {
app(ConnectionVerifier::class)->refreshToken($account);
$account->refresh();
}
$media = $postPlatform->post->mediaItems;