mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 04:11:13 -05:00
Fix: Resolve stale cache issues in moderation flow
This commit is contained in:
@@ -4,6 +4,7 @@ import { useToast } from "@/hooks/use-toast";
|
|||||||
import { logger } from "@/lib/logger";
|
import { logger } from "@/lib/logger";
|
||||||
import { getErrorMessage } from "@/lib/errorHandler";
|
import { getErrorMessage } from "@/lib/errorHandler";
|
||||||
import { MODERATION_CONSTANTS } from "@/lib/moderation/constants";
|
import { MODERATION_CONSTANTS } from "@/lib/moderation/constants";
|
||||||
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import type { User } from "@supabase/supabase-js";
|
import type { User } from "@supabase/supabase-js";
|
||||||
import {
|
import {
|
||||||
useEntityCache,
|
useEntityCache,
|
||||||
@@ -81,6 +82,7 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { user, isAdmin, isSuperuser, toast, settings } = config;
|
const { user, isAdmin, isSuperuser, toast, settings } = config;
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
// Initialize sub-hooks
|
// Initialize sub-hooks
|
||||||
const filters = useModerationFilters({
|
const filters = useModerationFilters({
|
||||||
@@ -379,7 +381,11 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
// Refresh stats to update counts
|
// Refresh stats to update counts
|
||||||
queue.refreshStats();
|
queue.refreshStats();
|
||||||
|
|
||||||
// Immediately refetch queue data to show fresh results
|
// Force cache invalidation before refetching to ensure fresh data
|
||||||
|
await queryClient.invalidateQueries({
|
||||||
|
queryKey: ['moderation-queue'],
|
||||||
|
exact: false // Invalidate all query variants
|
||||||
|
});
|
||||||
await queueQuery.refetch();
|
await queueQuery.refetch();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMsg = getErrorMessage(error);
|
const errorMsg = getErrorMessage(error);
|
||||||
|
|||||||
@@ -103,8 +103,12 @@ export function useQueueQuery(config: UseQueueQueryConfig): UseQueueQueryReturn
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create stable query key (TanStack Query uses this for caching/deduplication)
|
// Create stable query key (TanStack Query uses this for caching/deduplication)
|
||||||
|
// Include user context to ensure proper cache isolation per user/role
|
||||||
const queryKey = [
|
const queryKey = [
|
||||||
'moderation-queue',
|
'moderation-queue',
|
||||||
|
config.userId,
|
||||||
|
config.isAdmin,
|
||||||
|
config.isSuperuser,
|
||||||
config.entityFilter,
|
config.entityFilter,
|
||||||
config.statusFilter,
|
config.statusFilter,
|
||||||
config.tab,
|
config.tab,
|
||||||
|
|||||||
Reference in New Issue
Block a user