Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get ref #1203

Merged
merged 3 commits into from
Aug 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading