Skip to content

Commit

Permalink
POC: insert to system_package2 if applicable or installable update ex…
Browse files Browse the repository at this point in the history
…ists
  • Loading branch information
psegedy committed Nov 27, 2023
1 parent 2b7cd4e commit a2d0b8e
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions tasks/migration/migrate_system_package_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sync"

"gorm.io/gorm"
"gorm.io/gorm/clause"
)

var memoryPackageCache *evaluator.PackageCache
Expand Down Expand Up @@ -87,29 +88,33 @@ func processPartition(part string, i int) {
wg.Done()
}()
updates := getUpdates(as, part, i)
toInsert := make([]models.SystemPackage, 0, 1000)
for _, u := range updates {
updateData := getUpdateData(u, as, part, i)
latestApplicable, latestInstallable := getEvraApplicability(updateData)
applicableID, installableID := getPackageIDs(u, i, latestApplicable, latestInstallable)
if applicableID != 0 && installableID != 0 {
if applicableID != 0 || installableID != 0 {
// insert ids to system_package2
err := tasks.WithTx(func(db *gorm.DB) error {
return db.Table("system_package2").
Where("installable_id IS NULL AND applicable_id IS NULL").
Save(models.SystemPackage{
RhAccountID: as.RhAccountID,
SystemID: as.SystemID,
PackageID: u.PackageID,
NameID: u.NameID,
InstallableID: &installableID,
ApplicableID: &applicableID,
}).Error
})
if err != nil {
utils.LogWarn("#", i, "Failed to update system_package2")
sp := models.SystemPackage{
RhAccountID: as.RhAccountID,
SystemID: as.SystemID,
PackageID: u.PackageID,
NameID: u.NameID,
}
if installableID != 0 {
sp.InstallableID = &installableID
}
if applicableID != 0 {
sp.ApplicableID = &applicableID
}
toInsert = append(toInsert, sp)
}
}
tx = tx.Clauses(clause.OnConflict{DoNothing: true})
err := database.BulkInsert(tx, toInsert)
if err != nil {
utils.LogWarn("#", i, "Failed to update system_package2")
}
}(as, i, part)
}
wg.Wait()
Expand Down

0 comments on commit a2d0b8e

Please sign in to comment.