Skip to content

Commit

Permalink
RHINENG-11955: sort advisory_account_data before insert
Browse files Browse the repository at this point in the history
fix deadlocks when inserting to db in when processing multiple systems
  • Loading branch information
psegedy committed Nov 20, 2024
1 parent 5a1ff8f commit a3a7ced
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion evaluator/evaluate_advisories.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"app/base/models"
"app/base/utils"
"app/base/vmaas"
"cmp"
"slices"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -248,7 +250,7 @@ func storeAdvisoryData(tx *gorm.DB, system *models.SystemPlatform, advisoriesByN
return systemAdvisoriesNew, nil
}

func calcAdvisoryChanges(system *models.SystemPlatform,
func calcAdvisoryChanges(system *models.SystemPlatform, //nolint: funlen
advisoriesByName extendedAdvisoryMap) []models.AdvisoryAccountData {
// If system is stale, we won't change any rows in advisory_account_data
if system.Stale {
Expand Down Expand Up @@ -303,6 +305,12 @@ func calcAdvisoryChanges(system *models.SystemPlatform,
for _, aad := range aadMap {
aadSlice = append(aadSlice, aad)
}
slices.SortStableFunc(aadSlice, func(x, y models.AdvisoryAccountData) int {
if n := cmp.Compare(x.RhAccountID, y.RhAccountID); n != 0 {
return n
}
return cmp.Compare(x.AdvisoryID, y.AdvisoryID)
})
return aadSlice
}

Expand Down

0 comments on commit a3a7ced

Please sign in to comment.