From 83619eb98e99672cb8f2547cb036b0391f53fff7 Mon Sep 17 00:00:00 2001 From: Jonas Lochmann Date: Mon, 21 Nov 2022 01:00:00 +0100 Subject: [PATCH] Fix saving app list in the new format --- src/function/sync/apply-actions/cache.ts | 17 ------------- .../updateinstalledapps.ts | 24 +++++++++++++++++-- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/function/sync/apply-actions/cache.ts b/src/function/sync/apply-actions/cache.ts index f756a55..fcf9555 100644 --- a/src/function/sync/apply-actions/cache.ts +++ b/src/function/sync/apply-actions/cache.ts @@ -40,7 +40,6 @@ export class Cache { categoriesWithModifiedUsedTimes = new Set() categoriesWithModifiedTasks = new Set() - devicesWithModifiedInstalledApps = new Set() devicesWithModifiedShowDeviceConnected = new Map() invalidiateUserList = false @@ -241,22 +240,6 @@ export class Cache { this.categoriesWithModifiedUsedTimes.clear() } - if (this.devicesWithModifiedInstalledApps.size > 0) { - await database.device.update({ - installedAppsVersion: generateVersionId() - }, { - where: { - familyId, - deviceId: { - [Sequelize.Op.in]: setToList(this.devicesWithModifiedInstalledApps) - } - }, - transaction - }) - - this.devicesWithModifiedInstalledApps.clear() - } - if (this.invalidiateUserList) { await database.family.update({ userListVersion: generateVersionId() diff --git a/src/function/sync/apply-actions/dispatch-app-logic-action/updateinstalledapps.ts b/src/function/sync/apply-actions/dispatch-app-logic-action/updateinstalledapps.ts index bde22e9..fae4520 100644 --- a/src/function/sync/apply-actions/dispatch-app-logic-action/updateinstalledapps.ts +++ b/src/function/sync/apply-actions/dispatch-app-logic-action/updateinstalledapps.ts @@ -16,12 +16,32 @@ */ import { UpdateInstalledAppsAction } from '../../../../action' +import { types } from '../../../../database/encryptedapplist' +import { generateVersionId } from '../../../../util/token' import { Cache } from '../cache' -export async function dispatchUpdateInstalledApps (_: { +export async function dispatchUpdateInstalledApps ({ deviceId, action, cache }: { deviceId: string action: UpdateInstalledAppsAction cache: Cache }) { - // do nothing + async function upsert({ type, data }: { type: number, data: Buffer }) { + await cache.database.encryptedAppList.upsert({ + familyId: cache.familyId, + deviceId, + type, + version: generateVersionId(), + data + }, { transaction: cache.transaction }) + } + + if (action.base) { + await upsert({ type: types.base, data: action.base }) + } + + if (action.diff) { + await upsert({ type: types.diff, data: action.diff }) + } + + cache.incrementTriggeredSyncLevel(1) }