feat: Implement full Phase 3 API optimizations

This commit is contained in:
gpt-engineer-app[bot]
2025-10-30 23:02:26 +00:00
parent 46ca1c29bc
commit 0091584677
18 changed files with 654 additions and 243 deletions

View File

@@ -110,5 +110,81 @@ export function useQueryInvalidation() {
invalidateRides: () => {
queryClient.invalidateQueries({ queryKey: ['rides'] });
},
/**
* Invalidate park detail cache
* Call this after updating a park
*/
invalidateParkDetail: (slug: string) => {
queryClient.invalidateQueries({ queryKey: queryKeys.parks.detail(slug) });
},
/**
* Invalidate ride detail cache
* Call this after updating a ride
*/
invalidateRideDetail: (parkSlug: string, rideSlug: string) => {
queryClient.invalidateQueries({ queryKey: queryKeys.rides.detail(parkSlug, rideSlug) });
},
/**
* Invalidate entity reviews
* Call this after adding/updating/deleting reviews
*/
invalidateEntityReviews: (entityType: 'park' | 'ride', entityId: string) => {
queryClient.invalidateQueries({ queryKey: queryKeys.reviews.entity(entityType, entityId) });
},
/**
* Invalidate user reviews
* Call this after a user adds/updates/deletes their reviews
*/
invalidateUserReviews: (userId: string) => {
queryClient.invalidateQueries({ queryKey: ['reviews', 'user', userId] });
},
/**
* Invalidate entity photos
* Call this after uploading/deleting photos
*/
invalidateEntityPhotos: (entityType: string, entityId: string) => {
queryClient.invalidateQueries({ queryKey: queryKeys.photos.entity(entityType, entityId) });
},
/**
* Invalidate photo count
* Call this after photo changes
*/
invalidatePhotoCount: (entityType: string, entityId: string) => {
queryClient.invalidateQueries({ queryKey: queryKeys.photos.count(entityType, entityId) });
},
/**
* Invalidate search results
* Call this after major data changes
*/
invalidateSearchResults: () => {
queryClient.invalidateQueries({ queryKey: ['search'] });
},
/**
* Invalidate similar rides
* Call this after ride updates
*/
invalidateSimilarRides: (parkId: string, category: string) => {
queryClient.invalidateQueries({
queryKey: ['rides', 'similar', parkId, category]
});
},
/**
* Invalidate featured parks
* Call this after park updates that affect featured status
*/
invalidateFeaturedParks: () => {
queryClient.invalidateQueries({
queryKey: ['homepage', 'featured-parks']
});
},
};
}

View File

@@ -31,7 +31,50 @@ export const queryKeys = {
closingSoonRides: () => ['homepage', 'closing-soon-rides'] as const,
recentlyClosedParks: () => ['homepage', 'recently-closed-parks'] as const,
recentlyClosedRides: () => ['homepage', 'recently-closed-rides'] as const,
featuredParks: {
topRated: () => ['homepage', 'featured-parks', 'top-rated'] as const,
mostRides: () => ['homepage', 'featured-parks', 'most-rides'] as const,
},
},
// Add more query keys as needed
// Parks queries
parks: {
all: () => ['parks', 'all'] as const,
detail: (slug: string) => ['parks', 'detail', slug] as const,
rides: (parkId: string) => ['parks', 'rides', parkId] as const,
},
// Rides queries
rides: {
all: () => ['rides', 'all'] as const,
detail: (parkSlug: string, rideSlug: string) => ['rides', 'detail', parkSlug, rideSlug] as const,
similar: (parkId: string, category: string, currentId: string) =>
['rides', 'similar', parkId, category, currentId] as const,
},
// Reviews queries
reviews: {
entity: (entityType: 'park' | 'ride', entityId: string) =>
['reviews', entityType, entityId] as const,
user: (userId: string, filter: string, sortBy: string) =>
['reviews', 'user', userId, filter, sortBy] as const,
},
// Photos queries
photos: {
entity: (entityType: string, entityId: string) =>
['photos', entityType, entityId] as const,
count: (entityType: string, entityId: string) =>
['photos', 'count', entityType, entityId] as const,
},
// Search queries
search: {
global: (query: string) => ['search', 'global', query] as const,
},
// Lists queries
lists: {
items: (listId: string) => ['list-items', listId] as const,
},
} as const;