Skip to content

Commit

Permalink
Remove slow trigger (#6240)
Browse files Browse the repository at this point in the history
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
  • Loading branch information
kristina-fefelova authored Aug 3, 2024
1 parent c675f45 commit 7bf2a7c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 66 deletions.
2 changes: 1 addition & 1 deletion desktop-package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "desktop",
"version": "0.6.266",
"version": "0.6.271",
"main": "dist/main/electron.js",
"author": "Hardcore Engineering <hey@huly.io>",
"template": "@hcengineering/default-package",
Expand Down
2 changes: 1 addition & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hcengineering/desktop",
"version": "0.6.266",
"version": "0.6.271",
"main": "dist/main/electron.js",
"template": "@hcengineering/webpack-package",
"scripts": {
Expand Down
8 changes: 0 additions & 8 deletions models/server-notification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ export function createModel (builder: Builder): void {
TNotificationProviderResources
)

builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverNotification.trigger.OnActivityNotificationViewed,
txMatch: {
_class: core.class.TxUpdateDoc,
objectClass: notification.class.ActivityInboxNotification
}
})

builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverNotification.trigger.OnAttributeCreate,
txMatch: {
Expand Down
2 changes: 1 addition & 1 deletion plugins/activity-resources/src/activityMessagesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ export function isActivityMessage (message?: Doc): message is ActivityMessage {
return getClient().getHierarchy().isDerived(message._class, activity.class.ActivityMessage)
}

export function isReactionMessage (message?: ActivityMessage): boolean {
export function isReactionMessage (message?: ActivityMessage): message is DocUpdateMessage {
if (message === undefined) {
return false
}
Expand Down
12 changes: 11 additions & 1 deletion plugins/chunter-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { getClient } from '@hcengineering/presentation'
import { type AnySvelteComponent } from '@hcengineering/ui'
import { classIcon, getDocLinkTitle, getDocTitle } from '@hcengineering/view-resources'
import { get, writable, type Unsubscriber } from 'svelte/store'
import { isReactionMessage } from '@hcengineering/activity-resources'

import ChannelIcon from './components/ChannelIcon.svelte'
import DirectIcon from './components/DirectIcon.svelte'
Expand Down Expand Up @@ -439,7 +440,16 @@ export async function readChannelMessages (
const allIds = getAllIds(messages).filter((id) => !readMessages.has(id))

const notifications = get(inboxClient.activityInboxNotifications)
.filter(({ _id, attachedTo }) => allIds.includes(attachedTo))
.filter(({ attachedTo, $lookup, isViewed }) => {
if (isViewed) return false
const includes = allIds.includes(attachedTo)
if (includes) return true
const msg = $lookup?.attachedTo
if (isReactionMessage(msg)) {
return allIds.includes(msg.attachedTo as Ref<ActivityMessage>)
}
return false
})
.map((n) => n._id)

const relatedMentions = get(inboxClient.otherInboxNotifications)
Expand Down
53 changes: 0 additions & 53 deletions server-plugins/notification-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,58 +1516,6 @@ export async function removeDocInboxNotifications (_id: Ref<ActivityMessage>, co
)
}

async function OnActivityNotificationViewed (
tx: TxUpdateDoc<InboxNotification>,
control: TriggerControl
): Promise<Tx[]> {
if (tx.objectClass !== notification.class.ActivityInboxNotification || tx.operations.isViewed !== true) {
return []
}

const inboxNotification = (
await control.findAll(
notification.class.ActivityInboxNotification,
{
_id: tx.objectId as Ref<ActivityInboxNotification>
},
{ projection: { _id: 1, attachedTo: 1, user: 1 } }
)
)[0]

if (inboxNotification === undefined) {
return []
}

// Read reactions notifications when message is read
const { attachedTo, user } = inboxNotification

const reactionMessages = await control.findAll(
activity.class.DocUpdateMessage,
{
attachedTo,
objectClass: activity.class.Reaction
},
{ projection: { _id: 1 } }
)

if (reactionMessages.length === 0) {
return []
}

const reactionNotifications = await control.findAll(
notification.class.ActivityInboxNotification,
{
attachedTo: { $in: reactionMessages.map(({ _id }) => _id) },
user
},
{ projection: { _id: 1, _class: 1, space: 1 } }
)

return reactionNotifications.map(({ _id, _class, space }) =>
control.txFactory.createTxUpdateDoc(_class, space, _id, { isViewed: true })
)
}

export async function getCollaborators (
doc: Doc,
control: TriggerControl,
Expand Down Expand Up @@ -1659,7 +1607,6 @@ export default async () => ({
trigger: {
OnAttributeCreate,
OnAttributeUpdate,
OnActivityNotificationViewed,
OnDocRemove
},
function: {
Expand Down
1 change: 0 additions & 1 deletion server-plugins/notification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export default plugin(serverNotificationId, {
OnAttributeCreate: '' as Resource<TriggerFunc>,
OnAttributeUpdate: '' as Resource<TriggerFunc>,
OnReactionChanged: '' as Resource<TriggerFunc>,
OnActivityNotificationViewed: '' as Resource<TriggerFunc>,
OnDocRemove: '' as Resource<TriggerFunc>
},
function: {
Expand Down

0 comments on commit 7bf2a7c

Please sign in to comment.