perf(tiktok): load creator_info synchronously and cache it
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 <p>, and the now-orphaned posts.form.tiktok.creator_info_loading i18n key in en/pt-BR/es. ScheduleTab no longer passes the prop.
This commit is contained in:
parent
b9fd483894
commit
0682b6503c
7 changed files with 33 additions and 19 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<int, string>,
|
||||
* 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));
|
||||
|
|
|
|||
|
|
@ -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.',
|
||||
|
|
|
|||
|
|
@ -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.',
|
||||
|
|
|
|||
|
|
@ -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.',
|
||||
|
|
|
|||
|
|
@ -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] ?? {}"
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ interface Props {
|
|||
socialAccount: SocialAccount | null;
|
||||
publishConfig: Record<string, any> | null;
|
||||
creatorInfo?: CreatorInfo | null;
|
||||
creatorInfoLoading?: boolean;
|
||||
videoDurationSec?: number | null;
|
||||
contentType: string;
|
||||
meta: Record<string, any>;
|
||||
|
|
@ -49,7 +48,6 @@ interface Props {
|
|||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
creatorInfo: null,
|
||||
creatorInfoLoading: false,
|
||||
videoDurationSec: null,
|
||||
disabled: false,
|
||||
});
|
||||
|
|
@ -236,11 +234,6 @@ watch(
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="creatorInfoLoading" class="flex items-center gap-2 text-xs font-medium text-foreground/60">
|
||||
<span class="inline-block size-3 animate-pulse rounded-full bg-foreground/30" />
|
||||
{{ $t('posts.form.tiktok.creator_info_loading') }}
|
||||
</p>
|
||||
|
||||
<!-- Creator identity -->
|
||||
<div v-if="socialAccount" class="flex items-center gap-3 rounded-lg bg-foreground/5 p-3">
|
||||
<Avatar
|
||||
|
|
|
|||
Loading…
Reference in a new issue