Skip to content
Draft
Changes from 1 commit
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
24 changes: 22 additions & 2 deletions dashboard/entry/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ func (r *ResolverForEntry) UpdateDashboardEntry(ctx context.Context, id int, ent
entry.Total = *total
}

tx := r.DB.Begin()
if err := tx.Error; err != nil {
return nil, err
}
defer func() {
if r := recover(); r != nil {
tx.Rollback()
panic(r)
} else if tx != nil {
tx.Rollback()
}
}()

if stats != nil {
if stats.RangeID != nil {
if _, err := util.FindDashboardRange(r.DB, *stats.RangeID); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deadlocking test is likely fixed by using tx instead of r.DB here, as there may be only one connection and with the transaction open, r.DB cannot open a new connection.

if _, err := util.FindDashboardRange(tx, *stats.RangeID); err != nil {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, i missed that

Expand All @@ -61,7 +74,7 @@ func (r *ResolverForEntry) UpdateDashboardEntry(ctx context.Context, id int, ent
return nil, err
}

if err := r.DB.Where("dashboard_entry_id = ?", id).Delete(new(model.DashboardTagFilter)).Error; err != nil {
if err := tx.Where("dashboard_entry_id = ?", id).Delete(new(model.DashboardTagFilter)).Error; err != nil {
return nil, fmt.Errorf("failed to update tag filters: %s", err)
}

Expand All @@ -78,7 +91,14 @@ func (r *ResolverForEntry) UpdateDashboardEntry(ctx context.Context, id int, ent
return &gqlmodel.DashboardEntry{}, err
}

r.DB.Save(entry)
if err := tx.Save(entry).Error; err != nil {
return nil, err
}

if err := tx.Commit().Error; err != nil {
return nil, err
}

tx = nil
return convert.ToExternalEntry(entry)
}
Loading