UBERF-6807: fix empty objects channels in chat (#5533)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2024-05-07 16:36:34 +04:00 committed by GitHub
parent 6c2fdb520b
commit 56400846f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -24,7 +24,9 @@ import core, {
type Domain, type Domain,
type Ref, type Ref,
type TxCUD, type TxCUD,
type TxCollectionCUD type TxCollectionCUD,
type Class,
type DocumentQuery
} from '@hcengineering/core' } from '@hcengineering/core'
import { import {
tryMigrate, tryMigrate,
@ -237,16 +239,16 @@ async function migrateInboxNotifications (client: MigrationClient): Promise<void
} }
} }
export async function removeHiddenNotifications (client: MigrationClient): Promise<void> { export async function removeNotifications (
const processedIds: Ref<DocNotifyContext>[] = [] client: MigrationClient,
query: DocumentQuery<DocNotifyContext>
): Promise<void> {
while (true) { while (true) {
const contexts = await client.find<DocNotifyContext>( const contexts = await client.find<DocNotifyContext>(
DOMAIN_NOTIFICATION, DOMAIN_NOTIFICATION,
{ {
_class: notification.class.DocNotifyContext, _class: notification.class.DocNotifyContext,
_id: { $nin: processedIds }, ...query
hidden: true
}, },
{ limit: 500 } { limit: 500 }
) )
@ -257,8 +259,6 @@ export async function removeHiddenNotifications (client: MigrationClient): Promi
const ids = contexts.map(({ _id }) => _id) const ids = contexts.map(({ _id }) => _id)
processedIds.push(...ids)
await client.deleteMany(DOMAIN_NOTIFICATION, { await client.deleteMany(DOMAIN_NOTIFICATION, {
_class: notification.class.CommonInboxNotification, _class: notification.class.CommonInboxNotification,
docNotifyContext: { $in: ids } docNotifyContext: { $in: ids }
@ -268,6 +268,16 @@ export async function removeHiddenNotifications (client: MigrationClient): Promi
_class: notification.class.ActivityInboxNotification, _class: notification.class.ActivityInboxNotification,
docNotifyContext: { $in: ids } 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, [ await tryMigrate(client, notificationId, [
{ {
state: 'remove-hidden-notifications', state: 'delete-hidden-notifications',
func: removeHiddenNotifications 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<Class<Doc>> })
}
} }
]) ])
}, },