1// productProcessor.js 2self.onmessage = function(event) { 3 const { products } = event.data; 4 5 if (!products || !Array.isArray(products)) { 6 self.postMessage({ 7 type: 'error', 8 error: 'Invalid products data' 9 }); 10 return; 11 } 12 13 try { 14 const variantMap = new Map(); 15 const productMap = new Map(); 16 17 // Process products in chunks to avoid blocking 18 const chunkSize = 50; 19 let processedCount = 0; 20 21 for (let i = 0; i < products.length; i += chunkSize) { 22 const chunk = products.slice(i, i + chunkSize); 23 24 // Process each product in the chunk 25 chunk.forEach(product => { 26 if (product.variants && Array.isArray(product.variants)) { 27 product.variants.forEach(variant => { 28 if (variant.sku) { 29 variantMap.set(variant.sku, variant); 30 productMap.set(variant.sku, product); 31 } 32 }); 33 } 34 }); 35 36 processedCount += chunk.length; 37 38 // Send progress update 39 self.postMessage({ 40 type: 'progress', 41 progress: processedCount / products.length, 42 processedCount, 43 totalCount: products.length 44 }); 45 } 46 47 // Send final result 48 self.postMessage({ 49 type: 'complete', 50 processedData: products, 51 skuMaps: { 52 variantMap: Array.from(variantMap.entries()), 53 productMap: Array.from(productMap.entries()) 54 } 55 }); 56 } catch (error) { 57 self.postMessage({ 58 type: 'error', 59 error: error.message || 'Error processing products' 60 }); 61 } 62};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.