|
@@ -67,7 +67,15 @@ async function syncProductsToQdrant(
|
|
|
const startTime = new Date()
|
|
const startTime = new Date()
|
|
|
const collectionName = getCollectionName(storeName, 'products')
|
|
const collectionName = getCollectionName(storeName, 'products')
|
|
|
|
|
|
|
|
- console.log(`[Qdrant] Syncing ${products.length} products to ${collectionName}`)
|
|
|
|
|
|
|
+ // Filter out products without valid IDs
|
|
|
|
|
+ const validProducts = products.filter(p => p && p.id)
|
|
|
|
|
+
|
|
|
|
|
+ if (validProducts.length === 0) {
|
|
|
|
|
+ console.log('[Qdrant] No valid products to sync (all products missing IDs)')
|
|
|
|
|
+ return { synced: 0, errors: 0 }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.log(`[Qdrant] Syncing ${validProducts.length} products to ${collectionName}`)
|
|
|
|
|
|
|
|
let synced = 0
|
|
let synced = 0
|
|
|
let errors = 0
|
|
let errors = 0
|
|
@@ -93,7 +101,7 @@ async function syncProductsToQdrant(
|
|
|
existingPoints.points.map((p: any) => p.payload?.product_id).filter(Boolean)
|
|
existingPoints.points.map((p: any) => p.payload?.product_id).filter(Boolean)
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- const currentProductIds = new Set(products.map(p => p.id.toString()))
|
|
|
|
|
|
|
+ const currentProductIds = new Set(validProducts.map(p => p.id.toString()))
|
|
|
|
|
|
|
|
// Find deleted products
|
|
// Find deleted products
|
|
|
const deletedProductIds = Array.from(existingProductIds).filter(
|
|
const deletedProductIds = Array.from(existingProductIds).filter(
|
|
@@ -112,7 +120,7 @@ async function syncProductsToQdrant(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Generate text representations for all products
|
|
// Generate text representations for all products
|
|
|
- const productTexts = products.map((product) =>
|
|
|
|
|
|
|
+ const productTexts = validProducts.map((product) =>
|
|
|
createProductText({
|
|
createProductText({
|
|
|
name: product.name,
|
|
name: product.name,
|
|
|
description: product.description,
|
|
description: product.description,
|
|
@@ -132,7 +140,7 @@ async function syncProductsToQdrant(
|
|
|
console.log(`[Qdrant] Embeddings generated successfully`)
|
|
console.log(`[Qdrant] Embeddings generated successfully`)
|
|
|
|
|
|
|
|
// Convert products to Qdrant points with embeddings and comprehensive details
|
|
// Convert products to Qdrant points with embeddings and comprehensive details
|
|
|
- const points: QdrantPoint[] = products.map((product, index) => ({
|
|
|
|
|
|
|
+ const points: QdrantPoint[] = validProducts.map((product, index) => ({
|
|
|
id: generatePointId('shoprenter', storeId, product.id),
|
|
id: generatePointId('shoprenter', storeId, product.id),
|
|
|
vector: embeddings[index],
|
|
vector: embeddings[index],
|
|
|
payload: {
|
|
payload: {
|
|
@@ -378,14 +386,7 @@ serve(wrapHandler('shoprenter-sync', async (req) => {
|
|
|
const productsToCache = productsData.items.map((product: any) => ({
|
|
const productsToCache = productsData.items.map((product: any) => ({
|
|
|
store_id: storeId,
|
|
store_id: storeId,
|
|
|
shoprenter_product_id: product.id,
|
|
shoprenter_product_id: product.id,
|
|
|
- name: product.name,
|
|
|
|
|
- sku: product.sku,
|
|
|
|
|
- price: parseFloat(product.price) || 0,
|
|
|
|
|
- currency: product.currency || 'HUF',
|
|
|
|
|
- description: product.description,
|
|
|
|
|
- stock: product.stock,
|
|
|
|
|
- active: product.active !== false,
|
|
|
|
|
- raw_data: product,
|
|
|
|
|
|
|
+ product_data: product,
|
|
|
last_synced_at: new Date().toISOString()
|
|
last_synced_at: new Date().toISOString()
|
|
|
}))
|
|
}))
|
|
|
|
|
|