Improve image handling, optimize hooks, and add rate limiting

This commit introduces several improvements:
- Enhances `RideModelCard` by safely accessing and displaying ride count and image data, preventing potential errors.
- Refactors `useEntityVersions` and `useSearch` hooks to use `useCallback` and improve performance and prevent race conditions.
- Introduces a `MAX_MAP_SIZE` and cleanup mechanism for the rate limiting map in `detect-location` Supabase function to prevent memory leaks.
- Adds robust error handling and cleanup for image uploads in `uploadPendingImages`.
- Modifies `ManufacturerModels` to correctly map and display ride counts.
- Includes error handling for topological sort in `process-selective-approval` Supabase function.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 39bb006b-d046-477f-a1f9-b7821836f3a1
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
pac7
2025-10-08 17:55:37 +00:00
parent b17d36de03
commit 0f2219f849
8 changed files with 165 additions and 76 deletions

View File

@@ -25,16 +25,25 @@ export function RideModelCard({ model, manufacturerSlug }: RideModelCardProps) {
).join(' ');
};
const rideCount = (model as any).rides?.[0]?.count || 0;
// Safely extract ride count and image data
const extendedModel = model as RideModel & {
ride_count?: number;
card_image_url?: string;
card_image_id?: string;
};
const rideCount = extendedModel.ride_count || 0;
const cardImageUrl = extendedModel.card_image_url;
const cardImageId = extendedModel.card_image_id;
return (
<Card className="overflow-hidden hover:shadow-lg transition-shadow cursor-pointer group">
<div
className="aspect-video bg-gradient-to-br from-primary/10 via-secondary/10 to-accent/10 relative overflow-hidden"
>
{((model as any).card_image_url || (model as any).card_image_id) ? (
{(cardImageUrl || cardImageId) ? (
<img
src={(model as any).card_image_url || `https://imagedelivery.net/${import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH}/${(model as any).card_image_id}/public`}
src={cardImageUrl || `https://imagedelivery.net/${import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH}/${cardImageId}/public`}
alt={model.name}
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"
/>