-
Notifications
You must be signed in to change notification settings - Fork 465
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix: records update bugs and inefficiency #2941
Conversation
39fa78c
to
3e83b26
Compare
@@ -322,24 +313,27 @@ export async function update({ | |||
for (let i = 0; i < recordsWithoutDuplicates.length; i += BATCH_SIZE) { | |||
const chunk = recordsWithoutDuplicates.slice(i, i + BATCH_SIZE); | |||
|
|||
updatedKeys.push(...(await getUpdatedKeys({ records: chunk, connectionId, model, trx }))); | |||
const oldRecords = await getRecordsToUpdate({ records: chunk, connectionId, model, trx }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we used to make 2 queries to get the existing records to update. :(
|
||
const newRecord: FormattedRecord = { | ||
...oldRecordRest, | ||
...newRecordRest, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that was a bug. The only attributes that is different is the sync_job_id but was not updated
@@ -14,7 +14,7 @@ function isEncrypted(data: UnencryptedRecordData | EncryptedRecordData): data is | |||
return 'encryptedValue' in data; | |||
} | |||
|
|||
export function decryptRecord(record: FormattedRecord): UnencryptedRecordData { | |||
export function decryptRecordData(record: FormattedRecord): UnencryptedRecordData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renaming to make it clearer that the function only return the unencrypted data not the entire record
@@ -69,7 +69,7 @@ export const sendSync = async ({ | |||
responseResults?.added === 0 && responseResults?.updated === 0 && (responseResults.deleted === 0 || responseResults.deleted === undefined); | |||
|
|||
if (!webhookSettings.on_sync_completion_always && noChanges) { | |||
await logCtx?.info('There were no added, updated, or deleted results. No webhook sent, as per your environment settings'); | |||
await logCtx?.info(`There were no added, updated, or deleted results for model ${model}. No webhook sent, as per your environment settings`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated but it is confusing in the logs to see multiple times the same message when sync is multi model
updatedKeys.push(...(await getUpdatedKeys({ records: chunk, connectionId, model, trx }))); | ||
const chunkUpdatedKeys = await getUpdatedKeys({ records: chunk, connectionId, model, trx }); | ||
if (chunkUpdatedKeys.length === 0) { | ||
logger.warn(`Did not find records to update: ${{ connectionId, model }}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.warn does not exists (types are wrong), it's logger.warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3e83b26
to
33c5aa0
Compare
Describe your changes
Found a few small issues in the records update function as well as some inefficiency.
Checklist before requesting a review (skip if just adding/editing APIs & templates)