perf(admin-web): reduce redundant polling and cover active publish status
Unify list/detail poll intervals to 5s and skip refetch while a query is already in flight, replacing broad invalidateQueries cascades with targeted refetches. Poll now also triggers on active publish status via the new hasActivePublishStatus helper. Dedupe concurrent refreshBrands calls with a shared promise and skip the redundant AppShell refresh when already initialized. Gate publish-record loading on popover open. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,7 +17,12 @@ import { articlesApi, promptRulesApi } from '@/lib/api'
|
||||
import { buildArticleClipboardContent, resolveArticleActionState } from '@/lib/article-list-actions'
|
||||
import { useArticleRegenerateAction } from '@/lib/article-regenerate-action'
|
||||
import { copyTextToClipboard } from '@/lib/clipboard'
|
||||
import { getGenerateStatusMeta, getPublishStatusMeta } from '@/lib/display'
|
||||
import {
|
||||
getGenerateStatusMeta,
|
||||
getPublishStatusMeta,
|
||||
hasActiveGenerationStatus,
|
||||
hasActivePublishStatus,
|
||||
} from '@/lib/display'
|
||||
import { formatError } from '@/lib/errors'
|
||||
import { formatPublishPlatformList } from '@/lib/publish-platforms'
|
||||
import { useCompanyStore } from '@/stores/company'
|
||||
@@ -109,6 +114,7 @@ const listQuery = useQuery({
|
||||
})
|
||||
|
||||
let pollingTimer: number | null = null
|
||||
const ARTICLE_LIST_POLL_INTERVAL_MS = 5000
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: (id: number) => articlesApi.remove(id),
|
||||
@@ -205,8 +211,10 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
function startPolling(): void {
|
||||
if (pollingTimer !== null) return
|
||||
pollingTimer = window.setInterval(() => {
|
||||
void listQuery.refetch()
|
||||
}, 3000)
|
||||
if (!listQuery.isFetching.value) {
|
||||
void listQuery.refetch()
|
||||
}
|
||||
}, ARTICLE_LIST_POLL_INTERVAL_MS)
|
||||
}
|
||||
|
||||
function stopPolling(): void {
|
||||
@@ -236,7 +244,9 @@ watch(
|
||||
() => listQuery.data.value?.items ?? [],
|
||||
(items) => {
|
||||
const hasActive = items.some(
|
||||
(item) => item.generate_status === 'generating' || item.generate_status === 'running',
|
||||
(item) =>
|
||||
hasActiveGenerationStatus(item.generate_status) ||
|
||||
hasActivePublishStatus(item.publish_status),
|
||||
)
|
||||
if (hasActive) {
|
||||
startPolling()
|
||||
|
||||
Reference in New Issue
Block a user