@@ -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