Clean up from simplifying
This commit is contained in:
@@ -136,21 +136,6 @@ async function importCategories(prodConnection, localConnection) {
|
||||
total: totalInserted,
|
||||
elapsed: formatElapsedTime((Date.now() - startTime) / 1000),
|
||||
});
|
||||
|
||||
// Mark all products in these categories for recalculation
|
||||
if (categoriesToInsert.length > 0) {
|
||||
const affectedCatIds = categoriesToInsert.map(c => c.cat_id);
|
||||
|
||||
await localConnection.query(`
|
||||
INSERT INTO product_metric_status (pid, needs_recalculation)
|
||||
SELECT DISTINCT pc.pid, TRUE
|
||||
FROM product_categories pc
|
||||
WHERE pc.cat_id IN (?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
needs_recalculation = TRUE,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
`, [affectedCatIds]);
|
||||
}
|
||||
}
|
||||
|
||||
// After all imports, if we skipped any categories, throw an error
|
||||
|
||||
@@ -473,18 +473,6 @@ async function importOrders(prodConnection, localConnection, incrementalUpdate =
|
||||
recordsAdded += inserts;
|
||||
recordsUpdated += updates;
|
||||
importedCount += processedOrderItems.size;
|
||||
|
||||
// Mark affected products for recalculation
|
||||
const affectedPids = [...new Set(validOrders.map(o => o.pid))];
|
||||
if (affectedPids.length > 0) {
|
||||
await localConnection.query(`
|
||||
INSERT INTO product_metric_status (pid, needs_recalculation)
|
||||
VALUES ${affectedPids.map(() => '(?, TRUE)').join(',')}
|
||||
ON DUPLICATE KEY UPDATE
|
||||
needs_recalculation = TRUE,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
`, affectedPids);
|
||||
}
|
||||
}
|
||||
|
||||
// Update progress based on unique orders processed
|
||||
@@ -597,18 +585,6 @@ async function importOrders(prodConnection, localConnection, incrementalUpdate =
|
||||
recordsAdded += inserts;
|
||||
recordsUpdated += updates;
|
||||
importedCount += retryOrderItems.size;
|
||||
|
||||
// Mark affected products for recalculation
|
||||
const affectedPids = [...new Set(validOrders.map(o => o.pid))];
|
||||
if (affectedPids.length > 0) {
|
||||
await localConnection.query(`
|
||||
INSERT INTO product_metric_status (pid, needs_recalculation)
|
||||
VALUES ${affectedPids.map(() => '(?, TRUE)').join(',')}
|
||||
ON DUPLICATE KEY UPDATE
|
||||
needs_recalculation = TRUE,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
`, affectedPids);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Warning: Failed to retry skipped orders:', error.message);
|
||||
|
||||
@@ -203,8 +203,8 @@ async function materializeCalculations(prodConnection, localConnection, incremen
|
||||
});
|
||||
|
||||
// Insert all product data into temp table in batches
|
||||
for (let i = 0; i < prodData.length; i += 1000) {
|
||||
const batch = prodData.slice(i, i + 1000);
|
||||
for (let i = 0; i < prodData.length; i += 5000) {
|
||||
const batch = prodData.slice(i, i + 5000);
|
||||
const values = batch.map(row => [
|
||||
row.pid,
|
||||
row.title,
|
||||
@@ -315,7 +315,7 @@ async function materializeCalculations(prodConnection, localConnection, incremen
|
||||
outputProgress({
|
||||
status: "running",
|
||||
operation: "Products import",
|
||||
message: `Processed ${Math.min(i + 1000, prodData.length)} of ${prodData.length} product records`,
|
||||
message: `Processed ${Math.min(i + 5000, prodData.length)} of ${prodData.length} product records`,
|
||||
current: i + batch.length,
|
||||
total: prodData.length
|
||||
});
|
||||
@@ -473,14 +473,6 @@ async function importProducts(prodConnection, localConnection, incrementalUpdate
|
||||
...insertsAndUpdates.updates.map(p => p.pid),
|
||||
...insertsAndUpdates.inserts.map(p => p.pid)
|
||||
];
|
||||
|
||||
await localConnection.query(`
|
||||
INSERT INTO product_metric_status (pid, needs_recalculation)
|
||||
VALUES ${affectedPids.map(() => '(?, TRUE)').join(',')}
|
||||
ON DUPLICATE KEY UPDATE
|
||||
needs_recalculation = TRUE,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
`, affectedPids);
|
||||
}
|
||||
|
||||
// Process category relationships
|
||||
|
||||
@@ -474,18 +474,6 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
|
||||
recordsAdded += inserts;
|
||||
recordsUpdated += Math.floor(updates); // Ensure we never have fractional updates
|
||||
processed += batchProcessed;
|
||||
|
||||
// Mark affected products for recalculation
|
||||
const affectedPids = [...new Set(productBatch.map(p => p.pid))];
|
||||
if (affectedPids.length > 0) {
|
||||
await localConnection.query(`
|
||||
INSERT INTO product_metric_status (pid, needs_recalculation)
|
||||
VALUES ${affectedPids.map(() => '(?, TRUE)').join(',')}
|
||||
ON DUPLICATE KEY UPDATE
|
||||
needs_recalculation = TRUE,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
`, affectedPids);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle updates - now we know these actually have changes
|
||||
@@ -511,18 +499,6 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
|
||||
|
||||
recordsUpdated += Math.floor(updates); // Ensure we never have fractional updates
|
||||
processed += batchProcessed;
|
||||
|
||||
// Mark affected products for recalculation
|
||||
const affectedPids = [...new Set(productBatch.map(p => p.pid))];
|
||||
if (affectedPids.length > 0) {
|
||||
await localConnection.query(`
|
||||
INSERT INTO product_metric_status (pid, needs_recalculation)
|
||||
VALUES ${affectedPids.map(() => '(?, TRUE)').join(',')}
|
||||
ON DUPLICATE KEY UPDATE
|
||||
needs_recalculation = TRUE,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
`, affectedPids);
|
||||
}
|
||||
}
|
||||
|
||||
// Update progress based on time interval
|
||||
|
||||
Reference in New Issue
Block a user