From 56400846f38d169f80c495e505451865342103f5 Mon Sep 17 00:00:00 2001 From: Kristina Date: Tue, 7 May 2024 16:36:34 +0400 Subject: [PATCH] UBERF-6807: fix empty objects channels in chat (#5533) Signed-off-by: Kristina Fefelova --- models/notification/src/migration.ts | 40 +++++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/models/notification/src/migration.ts b/models/notification/src/migration.ts index 735130d4c7..18d71482e7 100644 --- a/models/notification/src/migration.ts +++ b/models/notification/src/migration.ts @@ -24,7 +24,9 @@ import core, { type Domain, type Ref, type TxCUD, - type TxCollectionCUD + type TxCollectionCUD, + type Class, + type DocumentQuery } from '@hcengineering/core' import { tryMigrate, @@ -237,16 +239,16 @@ async function migrateInboxNotifications (client: MigrationClient): Promise { - const processedIds: Ref[] = [] - +export async function removeNotifications ( + client: MigrationClient, + query: DocumentQuery +): Promise { while (true) { const contexts = await client.find( DOMAIN_NOTIFICATION, { _class: notification.class.DocNotifyContext, - _id: { $nin: processedIds }, - hidden: true + ...query }, { limit: 500 } ) @@ -257,8 +259,6 @@ export async function removeHiddenNotifications (client: MigrationClient): Promi const ids = contexts.map(({ _id }) => _id) - processedIds.push(...ids) - await client.deleteMany(DOMAIN_NOTIFICATION, { _class: notification.class.CommonInboxNotification, docNotifyContext: { $in: ids } @@ -268,6 +268,16 @@ export async function removeHiddenNotifications (client: MigrationClient): Promi _class: notification.class.ActivityInboxNotification, docNotifyContext: { $in: ids } }) + + await client.deleteMany(DOMAIN_NOTIFICATION, { + _class: notification.class.MentionInboxNotification, + docNotifyContext: { $in: ids } + }) + + await client.deleteMany(DOMAIN_NOTIFICATION, { + _class: notification.class.DocNotifyContext, + _id: { $in: ids } + }) } } @@ -281,8 +291,18 @@ export const notificationOperation: MigrateOperation = { ]) await tryMigrate(client, notificationId, [ { - state: 'remove-hidden-notifications', - func: removeHiddenNotifications + state: 'delete-hidden-notifications', + func: async (client) => { + await removeNotifications(client, { hidden: true }) + } + } + ]) + await tryMigrate(client, notificationId, [ + { + state: 'delete-invalid-notifications', + func: async (client) => { + await removeNotifications(client, { attachedToClass: 'chunter:class:Comment' as Ref> }) + } } ]) },