From 0682b6503c810b8dfad649d0a4a0c29b64b04988 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Sat, 9 May 2026 15:01:22 -0300 Subject: [PATCH] perf(tiktok): load creator_info synchronously and cache it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two related fixes that together eliminate the 'Loading your TikTok account settings…' flicker users were seeing on every keystroke / variant click in the post editor: 1. PostController::edit no longer wraps tiktokCreatorInfos in Inertia::defer. The map is computed during the initial render and shipped as a regular prop. Without defer, the prop never resets to null between Inertia visits, so the loading line never reappears. 2. TikTokCreatorInfo::fetch is now wrapped in a 5-minute Cache::remember keyed by social_account_id. Autosaves (which round-trip through PostController::update → back() → edit() again) used to issue a fresh TikTok API call for every connected account on every save — now the cache short-circuits them. Creator info changes very rarely (only when the user updates privacy settings on TikTok itself), so five minutes of staleness is acceptable; the worst case is a slightly out-of-date privacy-options list that corrects on next page load. Frontend cleanup: dropped the creatorInfoLoading prop, the inline loading

, and the now-orphaned posts.form.tiktok.creator_info_loading i18n key in en/pt-BR/es. ScheduleTab no longer passes the prop. --- app/Http/Controllers/App/PostController.php | 19 +++++++++------- app/Services/Social/TikTokCreatorInfo.php | 22 +++++++++++++++++++ lang/en/posts.php | 1 - lang/es/posts.php | 1 - lang/pt-BR/posts.php | 1 - .../components/posts/editor/ScheduleTab.vue | 1 - .../posts/editor/TikTokSettings.vue | 7 ------ 7 files changed, 33 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/App/PostController.php b/app/Http/Controllers/App/PostController.php index 83a695b4..e26d937d 100644 --- a/app/Http/Controllers/App/PostController.php +++ b/app/Http/Controllers/App/PostController.php @@ -232,7 +232,16 @@ public function edit(Request $request, Post $post): Response|RedirectResponse } } - $tiktokAccounts = $socialAccounts->where('platform', Platform::TikTok); + $tiktokCreatorInfos = $socialAccounts + ->where('platform', Platform::TikTok) + ->mapWithKeys(fn ($account) => [ + $account->id => rescue( + fn () => app(TikTokCreatorInfo::class)->fetch($account), + null, + report: false, + ), + ]) + ->filter(); return Inertia::render('posts/Edit', [ 'workspace' => $workspace, @@ -240,13 +249,7 @@ public function edit(Request $request, Post $post): Response|RedirectResponse 'socialAccounts' => $socialAccounts, 'platformConfigs' => $platformConfigs, 'pinterestBoards' => $pinterestBoards, - 'tiktokCreatorInfos' => Inertia::defer(fn () => $tiktokAccounts->mapWithKeys(fn ($account) => [ - $account->id => rescue( - fn () => app(TikTokCreatorInfo::class)->fetch($account), - null, - report: false, - ), - ])->filter()), + 'tiktokCreatorInfos' => $tiktokCreatorInfos, 'labels' => $labels, 'signatures' => $signatures, 'authUserId' => $request->user()->id, diff --git a/app/Services/Social/TikTokCreatorInfo.php b/app/Services/Social/TikTokCreatorInfo.php index b2237870..42a4858d 100644 --- a/app/Services/Social/TikTokCreatorInfo.php +++ b/app/Services/Social/TikTokCreatorInfo.php @@ -8,6 +8,7 @@ use App\Models\SocialAccount; use App\Services\Social\Concerns\HasSocialHttpClient; use Illuminate\Http\Client\PendingRequest; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; @@ -37,6 +38,27 @@ public function __construct() * } */ public function fetch(SocialAccount $account): array + { + return Cache::remember( + "tiktok:creator_info:{$account->id}", + now()->addMinutes(5), + fn () => $this->fetchFresh($account), + ); + } + + /** + * @return array{ + * creator_nickname: ?string, + * creator_username: ?string, + * creator_avatar_url: ?string, + * privacy_level_options: array, + * comment_disabled: bool, + * duet_disabled: bool, + * stitch_disabled: bool, + * max_video_post_duration_sec: ?int, + * } + */ + private function fetchFresh(SocialAccount $account): array { if ($account->is_token_expired || $account->is_token_expiring_soon) { $this->refreshTokenWithLock($account, fn () => $this->refreshToken($account)); diff --git a/lang/en/posts.php b/lang/en/posts.php index 11968b4a..1f7c4cc5 100644 --- a/lang/en/posts.php +++ b/lang/en/posts.php @@ -84,7 +84,6 @@ 'branded_cleared_private' => 'Privacy was cleared because Branded Content cannot be private.', 'interaction_disabled_by_creator' => 'Disabled by your TikTok account settings.', 'max_duration_exceeded' => 'Video is :duration s long but this account can only post videos up to :max s.', - 'creator_info_loading' => 'Loading your TikTok account settings…', 'processing_hint' => 'After publishing, it may take a few minutes for the content to process and appear on your TikTok profile.', 'brand_organic' => 'Your brand', 'brand_organic_hint' => 'You are promoting yourself or your own brand. This video will be classified as Brand Organic.', diff --git a/lang/es/posts.php b/lang/es/posts.php index 4d7d6077..f0c37f10 100644 --- a/lang/es/posts.php +++ b/lang/es/posts.php @@ -84,7 +84,6 @@ 'branded_cleared_private' => 'La visibilidad se borró porque el contenido de marca no puede ser privado.', 'interaction_disabled_by_creator' => 'Desactivado por la configuración de tu cuenta TikTok.', 'max_duration_exceeded' => 'El video dura :duration s pero esta cuenta solo permite videos de hasta :max s.', - 'creator_info_loading' => 'Cargando la configuración de tu cuenta TikTok…', 'processing_hint' => 'Después de publicar, puede tardar unos minutos en procesarse y aparecer en tu perfil de TikTok.', 'brand_organic' => 'Tu marca', 'brand_organic_hint' => 'Estás promocionándote a ti mismo o a tu propia marca. Este video será clasificado como Brand Organic.', diff --git a/lang/pt-BR/posts.php b/lang/pt-BR/posts.php index a369fa86..ee030523 100644 --- a/lang/pt-BR/posts.php +++ b/lang/pt-BR/posts.php @@ -84,7 +84,6 @@ 'branded_cleared_private' => 'A visibilidade foi limpa porque conteúdo de marca não pode ser privado.', 'interaction_disabled_by_creator' => 'Desativado pelas configurações da sua conta TikTok.', 'max_duration_exceeded' => 'Vídeo tem :duration s mas esta conta só permite vídeos de até :max s.', - 'creator_info_loading' => 'Carregando configurações da sua conta TikTok…', 'processing_hint' => 'Após publicar, pode levar alguns minutos para o conteúdo ser processado e aparecer no seu perfil TikTok.', 'brand_organic' => 'Sua marca', 'brand_organic_hint' => 'Você está promovendo você mesmo ou sua própria marca. Este vídeo será classificado como Brand Organic.', diff --git a/resources/js/components/posts/editor/ScheduleTab.vue b/resources/js/components/posts/editor/ScheduleTab.vue index 8fc366d6..ea201eca 100644 --- a/resources/js/components/posts/editor/ScheduleTab.vue +++ b/resources/js/components/posts/editor/ScheduleTab.vue @@ -266,7 +266,6 @@ const getPlatformAvatar = (pp: PostPlatform): string | null => :social-account="pp.social_account" :publish-config="getPublishConfig(pp)" :creator-info="getCreatorInfo(pp)" - :creator-info-loading="tiktokCreatorInfos === undefined || tiktokCreatorInfos === null" :video-duration-sec="videoDurationSec" :content-type="platformContentTypes[pp.id] ?? ''" :meta="platformMeta[pp.id] ?? {}" diff --git a/resources/js/components/posts/editor/TikTokSettings.vue b/resources/js/components/posts/editor/TikTokSettings.vue index c4511ee6..94018032 100644 --- a/resources/js/components/posts/editor/TikTokSettings.vue +++ b/resources/js/components/posts/editor/TikTokSettings.vue @@ -40,7 +40,6 @@ interface Props { socialAccount: SocialAccount | null; publishConfig: Record | null; creatorInfo?: CreatorInfo | null; - creatorInfoLoading?: boolean; videoDurationSec?: number | null; contentType: string; meta: Record; @@ -49,7 +48,6 @@ interface Props { const props = withDefaults(defineProps(), { creatorInfo: null, - creatorInfoLoading: false, videoDurationSec: null, disabled: false, }); @@ -236,11 +234,6 @@ watch( -

- - {{ $t('posts.form.tiktok.creator_info_loading') }} -

-