Skip to content

Commit

Permalink
fix get refs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitenjain14 committed Aug 10, 2023
1 parent 3a1a405 commit 87c50c8
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions code/go/0chain.net/blobbercore/reference/referencepath.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ func GetRefs(ctx context.Context, allocationID, path, offsetPath, _type string,

wg := sync.WaitGroup{}
wg.Add(2)
errChan := make(chan error, 2)
go func() {
_ = datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
err1 := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
tx := datastore.GetStore().GetTransaction(ctx)
db1 := tx.Model(&Ref{}).Where("allocation_id = ?", allocationID).
Where("path = ?", path).Or("path LIKE ?", path+"%")
db1 := tx.Model(&Ref{}).Where("allocation_id = ? AND (path=? OR path LIKE ?)", allocationID, path, path+"%")
if _type != "" {
db1 = db1.Where("type = ?", _type)
}
Expand All @@ -259,34 +259,42 @@ func GetRefs(ctx context.Context, allocationID, path, offsetPath, _type string,
db1 = db1.Where("path > ?", offsetPath)

db1 = db1.Order("path")
err = db1.Limit(pageLimit).Find(&pRefs).Error
err1 := db1.Limit(pageLimit).Find(&pRefs).Error
wg.Done()

return nil
return err1
})
if err1 != nil {
errChan <- err1
}

}()

go func() {
_ = datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
err2 := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
tx := datastore.GetStore().GetTransaction(ctx)
db2 := tx.Model(&Ref{}).Where("allocation_id = ?", allocationID).
Where("path = ?", path).Or("path LIKE ?", path+"%")
db2 := tx.Model(&Ref{}).Where("allocation_id = ? AND (path=? OR path LIKE ?)", allocationID, path, path+"%")
if _type != "" {
db2 = db2.Where("type = ?", _type)
}
if level != 0 {
db2 = db2.Where("level = ?", level)
}
db2.Count(&totalRows)
err2 := db2.Count(&totalRows).Error
wg.Done()

return nil
return err2
})
if err2 != nil {
errChan <- err2
}
}()
wg.Wait()
if err != nil {
return
close(errChan)
for err := range errChan {
if err != nil {
return nil, 0, "", err
}
}

refs = &pRefs
Expand All @@ -313,8 +321,7 @@ func GetUpdatedRefs(ctx context.Context, allocationID, path, offsetPath, _type,
go func() {
err := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
tx := datastore.GetStore().GetTransaction(ctx)
db1 := tx.Model(&Ref{}).Where("allocation_id = ?", allocationID).
Where("path = ?", path).Or("path LIKE ?", path+"%")
db1 := tx.Model(&Ref{}).Where("allocation_id = ? AND (path=? OR path LIKE ?)", allocationID, path, path+"%")
if _type != "" {
db1 = db1.Where("type = ?", _type)
}
Expand Down Expand Up @@ -343,8 +350,7 @@ func GetUpdatedRefs(ctx context.Context, allocationID, path, offsetPath, _type,
go func() {
err := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
tx := datastore.GetStore().GetTransaction(ctx)
db2 := tx.Model(&Ref{}).Where("allocation_id = ?", allocationID).
Where("path = ?", path).Or("path LIKE ?", path+"%")
db2 := tx.Model(&Ref{}).Where("allocation_id = ? AND (path=? OR path LIKE ?)", allocationID, path, path+"%")
if _type != "" {
db2 = db2.Where("type > ?", level)
}
Expand Down

0 comments on commit 87c50c8

Please sign in to comment.