From 4aba2493e5df227380b45d8c3f26d785e4b006bc Mon Sep 17 00:00:00 2001 From: William Grant Date: Mon, 21 Aug 2023 16:58:23 +1000 Subject: [PATCH] fix: remove convo volatile update from v34 migration since it's not related to disappearing messages --- ts/node/migration/helpers/v34.ts | 38 +++----------------------- ts/node/migration/sessionMigrations.ts | 33 +++------------------- 2 files changed, 8 insertions(+), 63 deletions(-) diff --git a/ts/node/migration/helpers/v34.ts b/ts/node/migration/helpers/v34.ts index 4567b3285..4eb97608a 100644 --- a/ts/node/migration/helpers/v34.ts +++ b/ts/node/migration/helpers/v34.ts @@ -3,12 +3,10 @@ import * as BetterSqlite3 from '@signalapp/better-sqlite3'; import { ContactInfoSet, ContactsConfigWrapperNode, - ConvoInfoVolatileWrapperNode, DisappearingMessageConversationType, } from 'libsession_util_nodejs'; -import { isEmpty, isEqual, isFinite, isNumber } from 'lodash'; +import { isEmpty, isEqual } from 'lodash'; import { CONVERSATION_PRIORITIES } from '../../../models/conversationAttributes'; -import { MESSAGES_TABLE, toSqliteBoolean } from '../../database_utility'; import { fromHexToArray } from '../../../session/utils/String'; import { checkTargetMigration, hasDebugEnvVariable } from '../utils'; import { ConfigDumpRow, CONFIG_DUMP_TABLE } from '../../../types/sqlSharedTypes'; @@ -122,12 +120,10 @@ function getContactInfoFromDBValues({ return wrapperContact; } -function insertContactIntoContactWrapper( +function updateContactInContactWrapper( contact: any, blockedNumbers: Array, - contactsConfigWrapper: ContactsConfigWrapperNode | null, // set this to null to only insert into the convo volatile wrapper (i.e. for ourConvo case) - volatileConfigWrapper: ConvoInfoVolatileWrapperNode, - db: BetterSqlite3.Database, + contactsConfigWrapper: ContactsConfigWrapperNode, version: number ) { checkTargetMigration(version, targetVersion); @@ -189,36 +185,10 @@ function insertContactIntoContactWrapper( } } } - - try { - const rows = db - .prepare( - ` - SELECT MAX(COALESCE(sent_at, 0)) AS max_sent_at - FROM ${MESSAGES_TABLE} WHERE - conversationId = $conversationId AND - unread = $unread; - ` - ) - .get({ - conversationId: contact.id, - unread: toSqliteBoolean(false), // we want to find the message read with the higher sentAt timestamp - }); - - const maxRead = rows?.max_sent_at; - const lastRead = isNumber(maxRead) && isFinite(maxRead) ? maxRead : 0; - hasDebugEnvVariable && - console.info(`Inserting contact into volatile wrapper maxread: ${contact.id} :${lastRead}`); - volatileConfigWrapper.set1o1(contact.id, lastRead, false); - } catch (e) { - console.error( - `volatileConfigWrapper.set1o1 during migration failed with ${e.message} for id: ${contact.id}. skipping` - ); - } } export const V34 = { fetchConfigDumps, writeConfigDumps, - insertContactIntoContactWrapper, + updateContactInContactWrapper, }; diff --git a/ts/node/migration/sessionMigrations.ts b/ts/node/migration/sessionMigrations.ts index 1c2bf2680..b0e04159e 100644 --- a/ts/node/migration/sessionMigrations.ts +++ b/ts/node/migration/sessionMigrations.ts @@ -1767,36 +1767,23 @@ function updateToSessionSchemaVersion34(currentVersion: number, db: BetterSqlite publicKeyHex, 'ContactsConfig' ); - const volatileInfoConfigWrapperDump = MIGRATION_HELPERS.V34.fetchConfigDumps( - db, - targetVersion, - publicKeyHex, - 'ConvoInfoVolatileConfig' - ); - if (contactsWrapperDump && volatileInfoConfigWrapperDump) { + if (contactsWrapperDump) { const contactsData = contactsWrapperDump.data; const contactsConfigWrapper = new ContactsConfigWrapperNode( privateEd25519, contactsData ); - const volatileInfoData = volatileInfoConfigWrapperDump.data; - const volatileInfoConfigWrapper = new ConvoInfoVolatileWrapperNode( - privateEd25519, - volatileInfoData - ); console.info( `===================== Starting contact update into wrapper ${contactsToUpdateInWrapper?.length} =======================` ); contactsToUpdateInWrapper.forEach(contact => { - MIGRATION_HELPERS.V34.insertContactIntoContactWrapper( + MIGRATION_HELPERS.V34.updateContactInContactWrapper( contact, blockedNumbers, contactsConfigWrapper, - volatileInfoConfigWrapper, - db, targetVersion ); }); @@ -1817,22 +1804,9 @@ function updateToSessionSchemaVersion34(currentVersion: number, db: BetterSqlite console.log( '===================== contacts config wrapper dump updated =======================' ); - - // dump the wrapper content and save it to the DB - MIGRATION_HELPERS.V34.writeConfigDumps( - db, - targetVersion, - publicKeyHex, - 'ConvoInfoVolatileConfig', - volatileInfoConfigWrapper.dump() - ); - - console.log( - '===================== convo info volatile config wrapper dump updated =======================' - ); } else { console.log( - '===================== contacts config or convo info volatile config wrapper dump found =======================' + '===================== contacts config config wrapper dump found =======================' ); } } @@ -1846,6 +1820,7 @@ function updateToSessionSchemaVersion34(currentVersion: number, db: BetterSqlite expirationType = $expirationType WHERE type = 'group' AND id LIKE '05%' AND expireTimer > 0;` ).run({ expirationType: 'deleteAfterSend' }); + // endregion // Message changes