Calculate script fixes

This commit is contained in:
2025-02-09 15:40:57 -05:00
parent 843ce71506
commit 7ff757203f
4 changed files with 112 additions and 59 deletions

View File

@@ -85,15 +85,19 @@ async function calculateFinancialMetrics(startTime, totalProducts, processedCoun
const [batch] = await connection.query(`
SELECT DISTINCT p.pid
FROM products p
LEFT JOIN orders o ON p.pid = o.pid AND o.updated > ?
LEFT JOIN orders o ON p.pid = o.pid
WHERE p.pid > ?
AND (
p.updated > ?
OR o.pid IS NOT NULL
OR EXISTS (
SELECT 1 FROM orders o2
WHERE o2.pid = p.pid
AND o2.updated > ?
)
)
ORDER BY p.pid
LIMIT ?
`, [lastCalculationTime, lastPid, lastCalculationTime, BATCH_SIZE]);
`, [lastPid, lastCalculationTime, lastCalculationTime, BATCH_SIZE]);
if (batch.length === 0) break;