Selaa lähdekoodia

fix: optimize ShopRenter category fetching to cache ALL categories once #108

- Fixed bug where category cache was only populated from new/changed products
- Now collects category IDs from ALL products (both new/changed and reused)
- Ensures each unique category is fetched exactly once per sync run
- Reduces API calls to ShopRenter and stays within rate limits
- Both new and reused products can now access the full category cache
Claude 4 kuukautta sitten
vanhempi
sitoutus
6ba6c7feb4
1 muutettua tiedostoa jossa 3 lisäystä ja 2 poistoa
  1. 3 2
      supabase/functions/shoprenter-sync/index.ts

+ 3 - 2
supabase/functions/shoprenter-sync/index.ts

@@ -224,9 +224,10 @@ async function syncProductsToQdrant(
 
 
     console.log(`[Qdrant] Products analysis: ${productsNeedingEmbedding.length} new/changed, ${productsToReuse.length} unchanged`)
     console.log(`[Qdrant] Products analysis: ${productsNeedingEmbedding.length} new/changed, ${productsToReuse.length} unchanged`)
 
 
-    // Collect all unique category IDs from all products
+    // Collect all unique category IDs from ALL products (both new/changed and reused)
+    // This ensures we only fetch each category once per sync run
     const uniqueCategoryIds = new Set<string>()
     const uniqueCategoryIds = new Set<string>()
-    for (const product of productsNeedingEmbedding) {
+    for (const product of validProducts) {
       const categoryRelations = product.productCategoryRelations || []
       const categoryRelations = product.productCategoryRelations || []
       for (const rel of categoryRelations) {
       for (const rel of categoryRelations) {
         const categoryId = extractCategoryId(rel.category?.href)
         const categoryId = extractCategoryId(rel.category?.href)