mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 18:11:12 -05:00
Enable admin-only stats and update subscriptions
Implement plan to fix database RPCs by migrating to photos table, update hooks to enable only on admin pages, switch real-time subscriptions to the photos table, and apply to remaining forms. Also disable analytics in development.
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { queryKeys } from '@/lib/queryKeys';
|
||||
import type { DatabaseStatistics } from '@/types/database-stats';
|
||||
|
||||
export function useAdminDatabaseStats() {
|
||||
const location = useLocation();
|
||||
const isAdminPage = location.pathname.startsWith('/admin');
|
||||
|
||||
return useQuery({
|
||||
queryKey: queryKeys.admin.databaseStats(),
|
||||
queryFn: async () => {
|
||||
@@ -15,7 +19,8 @@ export function useAdminDatabaseStats() {
|
||||
|
||||
return data as unknown as DatabaseStatistics;
|
||||
},
|
||||
enabled: isAdminPage, // Only run query on admin pages
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
refetchInterval: 60 * 1000, // Auto-refetch every 60 seconds
|
||||
refetchInterval: isAdminPage ? 60 * 1000 : false, // Only refetch on admin pages
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { queryKeys } from '@/lib/queryKeys';
|
||||
import type { RecentAddition } from '@/types/database-stats';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function useRecentAdditions(limit: number = 50, entityTypeFilter?: string) {
|
||||
const location = useLocation();
|
||||
const isAdminPage = location.pathname.startsWith('/admin');
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: queryKeys.admin.recentAdditions(limit),
|
||||
queryFn: async () => {
|
||||
@@ -18,8 +22,9 @@ export function useRecentAdditions(limit: number = 50, entityTypeFilter?: string
|
||||
|
||||
return data as unknown as RecentAddition[];
|
||||
},
|
||||
enabled: isAdminPage, // Only run query on admin pages
|
||||
staleTime: 2 * 60 * 1000, // 2 minutes
|
||||
refetchInterval: 30 * 1000, // Auto-refetch every 30 seconds
|
||||
refetchInterval: isAdminPage ? 30 * 1000 : false, // Only refetch on admin pages
|
||||
});
|
||||
|
||||
// Set up real-time subscriptions
|
||||
@@ -51,7 +56,7 @@ export function useRecentAdditions(limit: number = 50, entityTypeFilter?: string
|
||||
.subscribe(),
|
||||
supabase
|
||||
.channel('recent_additions_photos')
|
||||
.on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'entity_photos' }, () => {
|
||||
.on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'photos' }, () => {
|
||||
query.refetch();
|
||||
})
|
||||
.subscribe(),
|
||||
|
||||
Reference in New Issue
Block a user