Set up change tracking in core tables

This commit is contained in:
2025-02-02 15:06:20 -05:00
parent 12cab7473a
commit 22ad2d44db
9 changed files with 216 additions and 94 deletions

View File

@@ -474,6 +474,18 @@ 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
@@ -499,6 +511,18 @@ 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