@@ -200,31 +200,29 @@ const handleWorker = async () => {
200
200
try {
201
201
// console.log('queueController', queueController.data())
202
202
const notificationRef = admin . firestore ( ) . collection ( 'ecom_notifications' )
203
- const query = notificationRef . where ( 'ready_at' , '<=' , admin . firestore . Timestamp . now ( ) . toMillis ( ) )
204
203
const queueState = queueController . data ( )
205
- if ( queueState . running ) {
206
- if ( ! queueState . store_ids || ! queueState . store_ids . length ) {
207
- return
208
- }
209
- query . where ( 'store_id' , 'not-in' , queueState . store_ids )
204
+ if ( queueState . running && ( ! queueState . store_ids || ! queueState . store_ids . length ) ) {
205
+ return
210
206
}
211
- query . orderBy ( 'ready_at' ) . limit ( 20 )
207
+ const query = notificationRef
208
+ . where ( 'ready_at' , '<=' , admin . firestore . Timestamp . now ( ) . toMillis ( ) )
209
+ . orderBy ( 'ready_at' ) . limit ( 600 )
212
210
213
211
const notificationDocs = await query . get ( )
214
212
// console.log('notification docs', notificationDocs.empty)
215
213
const storeIds = [ ]
216
214
if ( ! notificationDocs . empty ) {
217
215
const docsToRun = [ ]
218
216
notificationDocs . forEach ( doc => {
219
- const data = doc . data ( )
220
- if ( ! storeIds . includes ( data . store_id ) ) {
221
- if ( storeIds . length >= 10 ) {
222
- // https://firebase.google.com/docs/firestore/query-data/queries#limitations_2
223
- return
217
+ if ( docsToRun . length < 20 ) {
218
+ const data = doc . data ( )
219
+ if ( ! queueState . store_ids . includes ( data . store_id ) ) {
220
+ if ( ! storeIds . includes ( data . store_id ) ) {
221
+ storeIds . push ( data . store_id )
222
+ }
223
+ docsToRun . push ( run ( doc , data ) )
224
224
}
225
- storeIds . push ( data . store_id )
226
225
}
227
- docsToRun . push ( run ( doc , data ) )
228
226
} )
229
227
queueControllerRef . doc ( queueController . id ) . set ( {
230
228
running : true ,
0 commit comments