Skip to content
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

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

TBonnin
Copy link
Collaborator

@TBonnin TBonnin commented Nov 4, 2024

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)

  • I added tests, otherwise the reason is:
  • I added observability, otherwise the reason is:
  • I added analytics, otherwise the reason is:

@TBonnin TBonnin force-pushed the tbonnin/fix-batch-update-nov4 branch 3 times, most recently from 39fa78c to 3e83b26 Compare November 5, 2024 00:19
@TBonnin TBonnin changed the title fix: records update small bugs + logging fix: records update bugs and inefficiency Nov 5, 2024
@@ -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 });
Copy link
Collaborator Author

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,
Copy link
Collaborator Author

@TBonnin TBonnin Nov 5, 2024

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 {
Copy link
Collaborator Author

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`);
Copy link
Collaborator Author

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 }}`);
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old man yells at cloud (1)

@TBonnin TBonnin force-pushed the tbonnin/fix-batch-update-nov4 branch from 3e83b26 to 33c5aa0 Compare November 5, 2024 13:28
@TBonnin TBonnin merged commit cbe5d24 into master Nov 5, 2024
21 checks passed
@TBonnin TBonnin deleted the tbonnin/fix-batch-update-nov4 branch November 5, 2024 13:48
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants