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) }