Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deleting lots of records (track_deletes=true) #1878

Merged
merged 1 commit into from Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 14 additions & 7 deletions packages/shared/lib/services/sync/data/delete.service.ts
Expand Up @@ -46,13 +46,20 @@ export const getDeletedKeys = async (dbTable: string, uniqueKey: string, nangoCo
};
});

await schema()
.from<DataRecord>(RECORDS_TABLE)
.where({
nango_connection_id: nangoConnectionId,
model
})
.insert(deletedResults);
// insert the deleted records into the main table in batch of 1000
// this is to avoid the error of too many variables in the query
await db.knex.transaction(async (trx) => {
const chunkSize = 1000;
for (let i = 0; i < deletedResults.length; i += chunkSize) {
await trx
.from<DataRecord>(RECORDS_TABLE)
.where({
nango_connection_id: nangoConnectionId,
model
})
.insert(deletedResults.slice(i, i + chunkSize));
}
});

return results.map((result: DataRecord) => result.external_id);
};
Expand Down