fix(parcel-sync): batch deleteMany to avoid PostgreSQL 32767 bind variable limit
Cluj-Napoca sync failed with 62,307 removed features exceeding the limit. Batch deletions in chunks of 30,000 in both sync-service and no-geom-sync. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -537,9 +537,12 @@ export async function syncNoGeometryParcels(
|
||||
}
|
||||
|
||||
if (staleIds.length > 0) {
|
||||
await prisma.gisFeature.deleteMany({
|
||||
where: { id: { in: staleIds } },
|
||||
});
|
||||
const BATCH = 30_000;
|
||||
for (let i = 0; i < staleIds.length; i += BATCH) {
|
||||
await prisma.gisFeature.deleteMany({
|
||||
where: { id: { in: staleIds.slice(i, i + BATCH) } },
|
||||
});
|
||||
}
|
||||
console.log(
|
||||
`[no-geom-sync] Cleanup: removed ${staleIds.length} stale/invalid no-geom records`,
|
||||
);
|
||||
|
||||
@@ -318,16 +318,19 @@ export async function syncLayer(
|
||||
// PostGIS not available yet — not critical, skip silently
|
||||
}
|
||||
|
||||
// Mark removed features
|
||||
// Mark removed features (batch to avoid PostgreSQL 32767 bind variable limit)
|
||||
if (removedObjIds.length > 0) {
|
||||
push({ phase: "Marcare șterse" });
|
||||
await prisma.gisFeature.deleteMany({
|
||||
where: {
|
||||
layerId,
|
||||
siruta,
|
||||
objectId: { in: removedObjIds },
|
||||
},
|
||||
});
|
||||
const BATCH = 30_000;
|
||||
for (let i = 0; i < removedObjIds.length; i += BATCH) {
|
||||
await prisma.gisFeature.deleteMany({
|
||||
where: {
|
||||
layerId,
|
||||
siruta,
|
||||
objectId: { in: removedObjIds.slice(i, i + BATCH) },
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Update sync run
|
||||
|
||||
Reference in New Issue
Block a user