Skip to content

Commit 22b1e91

Browse files
authored
Merge pull request Sofie-Automation#1554 from nrkno/fix/sofie-4149/custom-publish-fast-remove
2 parents cd69ccb + e38a9cb commit 22b1e91

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

meteor/server/publications/mountedTriggers.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ meteorCustomPublish(
3535
deviceId: {
3636
$in: deviceIds,
3737
},
38-
})
38+
}),
39+
PeripheralDevicePubSub.mountedTriggersForDevice
3940
)
4041
}
4142
)
@@ -55,7 +56,8 @@ meteorCustomPublish(
5556
pub,
5657
DeviceTriggerMountedActionAdlibsPreview.find({
5758
studioId,
58-
})
59+
}),
60+
PeripheralDevicePubSub.mountedTriggersForDevicePreview
5961
)
6062
}
6163
)
@@ -66,7 +68,11 @@ interface CustomOptimizedPublishChanges<DBObj extends { _id: ProtectedString<any
6668
removed: Set<DBObj['_id']>
6769
}
6870

69-
function cursorCustomPublish<T extends { _id: ProtectedString<any> }>(pub: CustomPublish<T>, cursor: Mongo.Cursor<T>) {
71+
function cursorCustomPublish<T extends { _id: ProtectedString<any> }>(
72+
pub: CustomPublish<T>,
73+
cursor: Mongo.Cursor<T>,
74+
publicationName: PeripheralDevicePubSub
75+
) {
7076
function createEmptyBuffer(): CustomOptimizedPublishChanges<T> {
7177
return {
7278
added: new Map(),
@@ -88,7 +94,7 @@ function cursorCustomPublish<T extends { _id: ProtectedString<any> }>(pub: Custo
8894
removed: Array.from(bufferToSend.removed.values()),
8995
})
9096
} catch (e) {
91-
logger.error(`Error while updating publication: ${stringifyError(e)}`)
97+
logger.error(`Error while updating publication ${publicationName}: ${stringifyError(e)}`)
9298
}
9399
}, PUBLICATION_DEBOUNCE)
94100

@@ -115,10 +121,14 @@ function cursorCustomPublish<T extends { _id: ProtectedString<any> }>(pub: Custo
115121
removed: (doc) => {
116122
if (!pub.isReady) return
117123
const id = doc._id
118-
buffer.removed.add(id)
119-
// if the document with the same id has been added before, clear the addition
120-
buffer.changed.delete(id)
121-
buffer.added.delete(id)
124+
if (buffer.added.has(id)) {
125+
// if the document with the same id has been added before, clear the addition
126+
buffer.added.delete(id)
127+
} else {
128+
// if not, mark the deletion and clear any possible changes
129+
buffer.removed.add(id)
130+
buffer.changed.delete(id)
131+
}
122132
bufferChanged()
123133
},
124134
})
@@ -127,5 +137,6 @@ function cursorCustomPublish<T extends { _id: ProtectedString<any> }>(pub: Custo
127137

128138
pub.onStop(() => {
129139
observer.stop()
140+
bufferChanged.cancel()
130141
})
131142
}

0 commit comments

Comments
 (0)