Skip to content

Commit 2a480c8

Browse files
committed
chore: simplify notification merge logic
1 parent 8790bfc commit 2a480c8

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

packages/live-status-gateway/src/collections/notifications/notificationsHandler.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { DBNotificationObj } from '@sofie-automation/corelib/dist/dataModel/Noti
88
import { PlaylistNotificationsHandler } from './playlistNotificationsHandler.js'
99
import { RundownNotificationsHandler } from './rundownNotificationsHandler.js'
1010
import _ from 'underscore'
11-
import { unprotectString } from '@sofie-automation/server-core-integration'
1211

1312
const THROTTLE_PERIOD_MS = 100
1413

@@ -59,33 +58,18 @@ export class NotificationsHandler extends PublicationCollection<
5958
}
6059

6160
private updateCollectionData(): boolean {
62-
const merged = new Map<string, DBNotificationObj>()
61+
const merged: DBNotificationObj[] = []
6362

64-
// Pull data from the playlist notifications handler's collection
65-
if (this._playlistNotificationsHandler) {
66-
const playlistDocs = this._playlistNotificationsHandler.getPublishedDocs()
67-
for (const d of playlistDocs) {
68-
if (d._id && !merged.has(unprotectString(d._id))) {
69-
merged.set(unprotectString(d._id), d)
70-
}
71-
}
63+
if (this._playlistNotificationsHandler && this._rundownNotificationsHandler) {
64+
merged.concat([
65+
...this._playlistNotificationsHandler.getPublishedDocs(),
66+
...this._rundownNotificationsHandler.getPublishedDocs(),
67+
])
7268
}
7369

74-
// Pull data from the rundown notifications handler's collection
75-
if (this._rundownNotificationsHandler) {
76-
const rundownDocs = this._rundownNotificationsHandler.getPublishedDocs()
77-
for (const d of rundownDocs) {
78-
if (d._id && !merged.has(unprotectString(d._id))) {
79-
merged.set(unprotectString(d._id), d)
80-
}
81-
}
82-
}
83-
84-
const newNotifications = Array.from(merged.values())
85-
86-
const hasAnythingChanged = !_.isEqual(this._collectionData, newNotifications)
70+
const hasAnythingChanged = !_.isEqual(this._collectionData, merged)
8771
if (hasAnythingChanged) {
88-
this._collectionData = newNotifications
72+
this._collectionData = merged
8973
}
9074

9175
return hasAnythingChanged

0 commit comments

Comments
 (0)