diff --git a/src/database/main.ts b/src/database/main.ts index 8da2766..2a823d9 100644 --- a/src/database/main.ts +++ b/src/database/main.ts @@ -17,8 +17,6 @@ import * as Sequelize from 'sequelize' import { AddDeviceTokenModelStatic, createAddDeviceTokenModel } from './adddevicetoken' -import { AppModelStatic, createAppModel } from './app' -import { AppActivityModelStatic, createAppActivityModel } from './appactivity' import { AuthTokenModelStatic, createAuthtokenModel } from './authtoken' import { CategoryModelStatic, createCategoryModel } from './category' import { CategoryAppModelStatic, createCategoryAppModel } from './categoryapp' @@ -49,8 +47,6 @@ export type Transaction = Sequelize.Transaction export interface Database { addDeviceToken: AddDeviceTokenModelStatic authtoken: AuthTokenModelStatic - app: AppModelStatic - appActivity: AppActivityModelStatic category: CategoryModelStatic categoryApp: CategoryAppModelStatic categoryNetworkId: CategoryNetworkIdModelStatic @@ -87,8 +83,6 @@ interface TransactionOptions { const createDatabase = (sequelize: Sequelize.Sequelize): Database => ({ addDeviceToken: createAddDeviceTokenModel(sequelize), authtoken: createAuthtokenModel(sequelize), - app: createAppModel(sequelize), - appActivity: createAppActivityModel(sequelize), category: createCategoryModel(sequelize), categoryApp: createCategoryAppModel(sequelize), childTask: createChildTaskModel(sequelize), diff --git a/src/database/migration/migrations/20221114-remove-apps-and-activities.ts b/src/database/migration/migrations/20221114-remove-apps-and-activities.ts new file mode 100644 index 0000000..56ac13b --- /dev/null +++ b/src/database/migration/migrations/20221114-remove-apps-and-activities.ts @@ -0,0 +1,31 @@ +/* + * server component for the TimeLimit App + * Copyright (C) 2019 - 2022 Jonas Lochmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import { QueryInterface, Sequelize, Transaction } from 'sequelize' + +export async function up (queryInterface: QueryInterface, sequelize: Sequelize) { + await sequelize.transaction({ + type: Transaction.TYPES.EXCLUSIVE + }, async (transaction) => { + await queryInterface.dropTable('Apps', { transaction }) + await queryInterface.dropTable('AppActivities', { transaction }) + }) +} + +export async function down() { + throw new Error('not possible') +} diff --git a/src/function/cleanup/delete-families.ts b/src/function/cleanup/delete-families.ts index a16ab37..514a553 100644 --- a/src/function/cleanup/delete-families.ts +++ b/src/function/cleanup/delete-families.ts @@ -1,6 +1,6 @@ /* * server component for the TimeLimit App - * Copyright (C) 2019 - 2020 Jonas Lochmann + * Copyright (C) 2019 - 2022 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -29,26 +29,6 @@ export async function deleteFamilies ({ database, familiyIds }: { } await database.transaction(async (transaction) => { - // app - await database.app.destroy({ - where: { - familyId: { - [Sequelize.Op.in]: familiyIds - } - }, - transaction - }) - - // app activity - await database.appActivity.destroy({ - where: { - familyId: { - [Sequelize.Op.in]: familiyIds - } - }, - transaction - }) - // category await database.category.destroy({ where: { diff --git a/src/function/device/remove-device.ts b/src/function/device/remove-device.ts index 840cbe3..87e09db 100644 --- a/src/function/device/remove-device.ts +++ b/src/function/device/remove-device.ts @@ -40,23 +40,6 @@ export async function removeDevice ({ database, familyId, deviceId, websocket, t throw new Conflict() } - // remove app entries - await database.app.destroy({ - where: { - familyId, - deviceId - }, - transaction - }) - - await database.appActivity.destroy({ - where: { - familyId, - deviceId - }, - transaction - }) - // remove as current device await database.user.update({ currentDevice: '' diff --git a/src/function/sync/apply-actions/dispatch-app-logic-action/addinstalledapps.ts b/src/function/sync/apply-actions/dispatch-app-logic-action/addinstalledapps.ts index 708c9a6..beead96 100644 --- a/src/function/sync/apply-actions/dispatch-app-logic-action/addinstalledapps.ts +++ b/src/function/sync/apply-actions/dispatch-app-logic-action/addinstalledapps.ts @@ -15,49 +15,13 @@ * along with this program. If not, see . */ -import * as Sequelize from 'sequelize' import { AddInstalledAppsAction } from '../../../../action' -import { AppAttributes, maxPackageNameLength } from '../../../../database/app' import { Cache } from '../cache' -import { ApplyActionException } from '../exception' -export async function dispatchAddInstalledApps ({ deviceId, action, cache }: { +export async function dispatchAddInstalledApps (_: { deviceId: string action: AddInstalledAppsAction cache: Cache }) { - action.apps.forEach((app) => { - if (app.packageName.length > maxPackageNameLength) { - throw new ApplyActionException({ - staticMessage: 'package name too long', - dynamicMessage: 'package name too long: ' + app.packageName - }) - } - }) - - await cache.database.app.destroy({ - where: { - familyId: cache.familyId, - deviceId, - packageName: { - [Sequelize.Op.in]: action.apps.map((app) => app.packageName) - } - }, - transaction: cache.transaction - }) - - await cache.database.app.bulkCreate( - action.apps.map((app): AppAttributes => ({ - familyId: cache.familyId, - deviceId, - packageName: app.packageName, - title: app.title, - isLaunchable: app.isLaunchable, - recommendation: app.recommendation - })), - { transaction: cache.transaction } - ) - - cache.devicesWithModifiedInstalledApps.add(deviceId) - cache.incrementTriggeredSyncLevel(1) + // do nothing } diff --git a/src/function/sync/apply-actions/dispatch-app-logic-action/removeinstalledapps.ts b/src/function/sync/apply-actions/dispatch-app-logic-action/removeinstalledapps.ts index aa28b34..3ada864 100644 --- a/src/function/sync/apply-actions/dispatch-app-logic-action/removeinstalledapps.ts +++ b/src/function/sync/apply-actions/dispatch-app-logic-action/removeinstalledapps.ts @@ -15,26 +15,13 @@ * along with this program. If not, see . */ -import * as Sequelize from 'sequelize' import { RemoveInstalledAppsAction } from '../../../../action' import { Cache } from '../cache' -export async function dispatchRemoveInstalledApps ({ deviceId, action, cache }: { +export async function dispatchRemoveInstalledApps (_: { deviceId: string action: RemoveInstalledAppsAction cache: Cache }) { - await cache.database.app.destroy({ - where: { - familyId: cache.familyId, - deviceId, - packageName: { - [Sequelize.Op.in]: action.packageNames - } - }, - transaction: cache.transaction - }) - - cache.devicesWithModifiedInstalledApps.add(deviceId) - cache.incrementTriggeredSyncLevel(1) + // do nothing } diff --git a/src/function/sync/apply-actions/dispatch-app-logic-action/updateappactivities.ts b/src/function/sync/apply-actions/dispatch-app-logic-action/updateappactivities.ts index 55cbfb1..cbe08b1 100644 --- a/src/function/sync/apply-actions/dispatch-app-logic-action/updateappactivities.ts +++ b/src/function/sync/apply-actions/dispatch-app-logic-action/updateappactivities.ts @@ -15,85 +15,13 @@ * along with this program. If not, see . */ -import { chunk } from 'lodash' -import * as Sequelize from 'sequelize' import { UpdateAppActivitiesAction } from '../../../../action' -import { AppActivityAttributes, maxActivityNameLength, maxPackageNameLength } from '../../../../database/appactivity' import { Cache } from '../cache' -import { ApplyActionException } from '../exception' -export async function dispatchUpdateAppActivities ({ deviceId, action, cache }: { +export async function dispatchUpdateAppActivities (_: { deviceId: string action: UpdateAppActivitiesAction cache: Cache }) { - action.updatedOrAdded.forEach((app) => { - if (app.packageName.length > maxPackageNameLength) { - throw new ApplyActionException({ - staticMessage: 'package name too long', - dynamicMessage: 'package name too long: ' + app.packageName - }) - } - - if (app.activityName.length > maxActivityNameLength) { - throw new ApplyActionException({ - staticMessage: 'activity name too long', - dynamicMessage: 'activity name too long: ' + app.activityName - }) - } - }) - - if (action.updatedOrAdded.length > 0) { - const chuncks = chunk(action.updatedOrAdded, 500) - - for (const items of chuncks) { - await cache.database.appActivity.destroy({ - where: { - familyId: cache.familyId, - deviceId, - [Sequelize.Op.or]: ( - items.map((item) => ({ - packageName: item.packageName, - activityName: item.activityName - })) - ) - }, - transaction: cache.transaction - }) - } - - await cache.database.appActivity.bulkCreate( - action.updatedOrAdded.map((item): AppActivityAttributes => ({ - familyId: cache.familyId, - deviceId, - packageName: item.packageName, - activityName: item.activityName, - title: item.title - })), - { transaction: cache.transaction } - ) - } - - if (action.removed.length > 0) { - const chunks = chunk(action.removed, 500) - - for (const items of chunks) { - await cache.database.appActivity.destroy({ - where: { - familyId: cache.familyId, - deviceId, - [Sequelize.Op.or]: ( - items.map((item) => ({ - packageName: item.packageName, - activityName: item.activityName - })) - ) - }, - transaction: cache.transaction - }) - } - } - - cache.devicesWithModifiedInstalledApps.add(deviceId) - cache.incrementTriggeredSyncLevel(1) + // do nothing } 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 6fac11f..bde22e9 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,44 +16,12 @@ */ import { UpdateInstalledAppsAction } from '../../../../action' -import { types } from '../../../../database/encryptedapplist' -import { generateVersionId } from '../../../../util/token' import { Cache } from '../cache' -export async function dispatchUpdateInstalledApps ({ deviceId, action, cache }: { +export async function dispatchUpdateInstalledApps (_: { deviceId: string action: UpdateInstalledAppsAction cache: Cache }) { - 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 }) - } - - if (action.wipe) { - await cache.database.app.destroy({ - where: { - familyId: cache.familyId, - deviceId - }, - transaction: cache.transaction - }) - - cache.devicesWithModifiedInstalledApps.add(deviceId) - } - - cache.incrementTriggeredSyncLevel(1) + // do nothing }