@@ -233,6 +233,35 @@ func (pg *PostgreSQL) GetDocumentByID(auth model.Auth, dbName, col, id string) (
233
233
return doc .Data , nil
234
234
}
235
235
236
+ func (pg * PostgreSQL ) GetDocumentsByIDs (auth model.Auth , dbName , col string , ids []string ) (docs []map [string ]interface {}, err error ) {
237
+ where := secureRead (auth , col )
238
+
239
+ qry := fmt .Sprintf (`
240
+ SELECT *
241
+ FROM %s.%s
242
+ %s AND id in ('%s'::uuid)
243
+ ` , dbName , model .CleanCollectionName (col ), where , strings .Join (ids , "'::uuid,'" ))
244
+
245
+ rows , err := pg .DB .Query (qry , auth .AccountID , auth .UserID )
246
+ if err != nil {
247
+ return []map [string ]interface {}{}, err
248
+ }
249
+ defer rows .Close ()
250
+
251
+ for rows .Next () {
252
+ var doc Document
253
+ if err = scanDocument (rows , & doc ); err != nil {
254
+ return []map [string ]interface {}{}, err
255
+ }
256
+
257
+ doc .Data [FieldID ] = doc .ID
258
+ doc .Data [FieldAccountID ] = doc .AccountID
259
+ docs = append (docs , doc .Data )
260
+ }
261
+
262
+ return docs , nil
263
+ }
264
+
236
265
func (pg * PostgreSQL ) UpdateDocument (auth model.Auth , dbName , col , id string , doc map [string ]interface {}) (map [string ]interface {}, error ) {
237
266
where := secureWrite (auth , col )
238
267
@@ -265,12 +294,12 @@ func (pg *PostgreSQL) UpdateDocuments(auth model.Auth, dbName, col string, filte
265
294
where := secureWrite (auth , col )
266
295
where = applyFilter (where , filters )
267
296
268
- var idsForUpdate []string
297
+ var ids []string
269
298
qry := fmt .Sprintf (`
270
299
SELECT id
271
300
FROM %s.%s
272
301
%s
273
- ` , dbName , internal .CleanCollectionName (col ), where )
302
+ ` , dbName , model .CleanCollectionName (col ), where )
274
303
275
304
rows , err := pg .DB .Query (qry , auth .AccountID , auth .UserID )
276
305
if err != nil {
@@ -282,9 +311,9 @@ func (pg *PostgreSQL) UpdateDocuments(auth model.Auth, dbName, col string, filte
282
311
pg .log .Error ().Err (err ).Msg ("error occurred during scanning id for UpdateDocument event" )
283
312
continue
284
313
}
285
- idsForUpdate = append (idsForUpdate , id )
314
+ ids = append (ids , id )
286
315
}
287
- if len (idsForUpdate ) == 0 {
316
+ if len (ids ) == 0 {
288
317
return 0 , nil
289
318
}
290
319
@@ -308,13 +337,12 @@ func (pg *PostgreSQL) UpdateDocuments(auth model.Auth, dbName, col string, filte
308
337
}
309
338
310
339
go func () {
311
- for _ , id := range idsForUpdate {
312
- doc , err := pg .GetDocumentByID (auth , dbName , col , id )
313
- if err != nil {
314
- pg .log .Error ().Err (err ).Msgf ("the document with id=%s is not received for publishDocument event" , id )
315
- continue
316
- }
317
- pg .PublishDocument ("db-" + col , internal .MsgTypeDBUpdated , doc )
340
+ docs , err := pg .GetDocumentsByIDs (auth , dbName , col , ids )
341
+ if err != nil {
342
+ pg .log .Error ().Err (err ).Msgf ("the documents with ids=%#s are not received for publishDocument event" , ids )
343
+ }
344
+ for _ , doc := range docs {
345
+ pg .PublishDocument ("db-" + col , model .MsgTypeDBUpdated , doc )
318
346
}
319
347
}()
320
348
return
0 commit comments