@@ -244,11 +244,11 @@ func GetRefs(ctx context.Context, allocationID, path, offsetPath, _type string,
244
244
245
245
wg := sync.WaitGroup {}
246
246
wg .Add (2 )
247
+ errChan := make (chan error , 2 )
247
248
go func () {
248
- _ = datastore .GetStore ().WithNewTransaction (func (ctx context.Context ) error {
249
+ err1 : = datastore .GetStore ().WithNewTransaction (func (ctx context.Context ) error {
249
250
tx := datastore .GetStore ().GetTransaction (ctx )
250
- db1 := tx .Model (& Ref {}).Where ("allocation_id = ?" , allocationID ).
251
- Where ("path = ?" , path ).Or ("path LIKE ?" , path + "%" )
251
+ db1 := tx .Model (& Ref {}).Where ("allocation_id = ? AND (path=? OR path LIKE ?)" , allocationID , path , path + "%" )
252
252
if _type != "" {
253
253
db1 = db1 .Where ("type = ?" , _type )
254
254
}
@@ -259,34 +259,42 @@ func GetRefs(ctx context.Context, allocationID, path, offsetPath, _type string,
259
259
db1 = db1 .Where ("path > ?" , offsetPath )
260
260
261
261
db1 = db1 .Order ("path" )
262
- err = db1 .Limit (pageLimit ).Find (& pRefs ).Error
262
+ err1 : = db1 .Limit (pageLimit ).Find (& pRefs ).Error
263
263
wg .Done ()
264
264
265
- return nil
265
+ return err1
266
266
})
267
+ if err1 != nil {
268
+ errChan <- err1
269
+ }
267
270
268
271
}()
269
272
270
273
go func () {
271
- _ = datastore .GetStore ().WithNewTransaction (func (ctx context.Context ) error {
274
+ err2 : = datastore .GetStore ().WithNewTransaction (func (ctx context.Context ) error {
272
275
tx := datastore .GetStore ().GetTransaction (ctx )
273
- db2 := tx .Model (& Ref {}).Where ("allocation_id = ?" , allocationID ).
274
- Where ("path = ?" , path ).Or ("path LIKE ?" , path + "%" )
276
+ db2 := tx .Model (& Ref {}).Where ("allocation_id = ? AND (path=? OR path LIKE ?)" , allocationID , path , path + "%" )
275
277
if _type != "" {
276
278
db2 = db2 .Where ("type = ?" , _type )
277
279
}
278
280
if level != 0 {
279
281
db2 = db2 .Where ("level = ?" , level )
280
282
}
281
- db2 .Count (& totalRows )
283
+ err2 := db2 .Count (& totalRows ). Error
282
284
wg .Done ()
283
285
284
- return nil
286
+ return err2
285
287
})
288
+ if err2 != nil {
289
+ errChan <- err2
290
+ }
286
291
}()
287
292
wg .Wait ()
288
- if err != nil {
289
- return
293
+ close (errChan )
294
+ for err := range errChan {
295
+ if err != nil {
296
+ return nil , 0 , "" , err
297
+ }
290
298
}
291
299
292
300
refs = & pRefs
@@ -313,8 +321,7 @@ func GetUpdatedRefs(ctx context.Context, allocationID, path, offsetPath, _type,
313
321
go func () {
314
322
err := datastore .GetStore ().WithNewTransaction (func (ctx context.Context ) error {
315
323
tx := datastore .GetStore ().GetTransaction (ctx )
316
- db1 := tx .Model (& Ref {}).Where ("allocation_id = ?" , allocationID ).
317
- Where ("path = ?" , path ).Or ("path LIKE ?" , path + "%" )
324
+ db1 := tx .Model (& Ref {}).Where ("allocation_id = ? AND (path=? OR path LIKE ?)" , allocationID , path , path + "%" )
318
325
if _type != "" {
319
326
db1 = db1 .Where ("type = ?" , _type )
320
327
}
@@ -343,8 +350,7 @@ func GetUpdatedRefs(ctx context.Context, allocationID, path, offsetPath, _type,
343
350
go func () {
344
351
err := datastore .GetStore ().WithNewTransaction (func (ctx context.Context ) error {
345
352
tx := datastore .GetStore ().GetTransaction (ctx )
346
- db2 := tx .Model (& Ref {}).Where ("allocation_id = ?" , allocationID ).
347
- Where ("path = ?" , path ).Or ("path LIKE ?" , path + "%" )
353
+ db2 := tx .Model (& Ref {}).Where ("allocation_id = ? AND (path=? OR path LIKE ?)" , allocationID , path , path + "%" )
348
354
if _type != "" {
349
355
db2 = db2 .Where ("type > ?" , level )
350
356
}
0 commit comments