From a2d0b8ee01a3a28e06077f7a398fb90cffed57a1 Mon Sep 17 00:00:00 2001 From: Patrik Segedy Date: Mon, 27 Nov 2023 15:42:42 +0100 Subject: [PATCH] POC: insert to system_package2 if applicable or installable update exists --- .../migration/migrate_system_package_data.go | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/tasks/migration/migrate_system_package_data.go b/tasks/migration/migrate_system_package_data.go index b681a252c..5220d911e 100644 --- a/tasks/migration/migrate_system_package_data.go +++ b/tasks/migration/migrate_system_package_data.go @@ -13,6 +13,7 @@ import ( "sync" "gorm.io/gorm" + "gorm.io/gorm/clause" ) var memoryPackageCache *evaluator.PackageCache @@ -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()