Skip to content

Commit

Permalink
call cursor.update during backup field migration, needs new version
Browse files Browse the repository at this point in the history
  • Loading branch information
bwindels committed Feb 1, 2022
1 parent 00c5e74 commit 2e3616e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/matrix/storage/idb/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const schema: MigrationFunc[] = [
changeSSSSKeyPrefix,
backupAndRestoreE2EEAccountToLocalStorage,
clearAllStores,
addInboundSessionBackupIndex
addInboundSessionBackupIndex,
migrateBackupStatus
];
// TODO: how to deal with git merge conflicts of this array?

Expand Down Expand Up @@ -280,6 +281,13 @@ async function clearAllStores(db: IDBDatabase, txn: IDBTransaction) {

// v15 add backup index to inboundGroupSessions
async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction, localStorage: IDOMStorage, log: ILogItem): Promise<void> {
const inboundGroupSessions = txn.objectStore("inboundGroupSessions");
inboundGroupSessions.createIndex("byBackup", "backup", {unique: false});
}


// v16 migrates the backup and source fields of inbound group sessions
async function migrateBackupStatus(db: IDBDatabase, txn: IDBTransaction, localStorage: IDOMStorage, log: ILogItem): Promise<void> {
const inboundGroupSessions = txn.objectStore("inboundGroupSessions");
let countWithSession = 0;
let countWithoutSession = 0;
Expand All @@ -291,6 +299,7 @@ async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction
// to backup keys that were already in backup, which
// the server will ignore
value.source = KeySource.DeviceMessage;
cursor.update(value);
countWithSession += 1;
} else {
countWithoutSession += 1;
Expand All @@ -299,5 +308,4 @@ async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction
});
log.set("countWithoutSession", countWithoutSession);
log.set("countWithSession", countWithSession);
inboundGroupSessions.createIndex("byBackup", "backup", {unique: false});
}

0 comments on commit 2e3616e

Please sign in to comment.