Improve import scripts with enhanced incremental update tracking and performance

- Add record tracking for added and updated records in import scripts
- Modify products import to use a dynamic 'needs_update' flag for selective updates
- Enhance order import with more comprehensive timestamp checks
- Update import-from-prod.js to handle and clean up previously running imports
- Improve error handling and connection management in import processes
This commit is contained in:
2025-01-31 01:39:48 -05:00
parent 1be97d6610
commit 5e4d1c3bd8
4 changed files with 72 additions and 25 deletions

View File

@@ -2,6 +2,8 @@ const { outputProgress, formatElapsedTime, estimateRemaining, calculateRate } =
async function importPurchaseOrders(prodConnection, localConnection, incrementalUpdate = true) {
const startTime = Date.now();
let recordsAdded = 0;
let recordsUpdated = 0;
try {
// Get last sync info
@@ -29,16 +31,19 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
// Build incremental conditions
const incrementalWhereClause = incrementalUpdate
? `AND (
p.date_updated > ?
p.stamp > ?
OR p.date_updated > ?
OR p.date_ordered > ?
OR p.date_estin > ?
OR r.stamp > ?
OR r.date_updated > ?
OR r.date_created > ?
OR r.date_checked > ?
OR rp.stamp > ?
OR rp.received_date > ?
)`
: "";
const incrementalParams = incrementalUpdate
? [lastSyncTime, lastSyncTime, lastSyncTime, lastSyncTime, lastSyncTime, lastSyncTime]
? [lastSyncTime, lastSyncTime, lastSyncTime, lastSyncTime, lastSyncTime, lastSyncTime, lastSyncTime, lastSyncTime, lastSyncTime]
: [];
// First get all relevant PO IDs with basic info
@@ -98,8 +103,6 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
const totalItems = total;
let processed = 0;
let recordsAdded = 0;
let recordsUpdated = 0;
const BATCH_SIZE = 5000;
const PROGRESS_INTERVAL = 500;