diff options
author | 2024-03-21 20:19:40 +0200 | |
---|---|---|
committer | 2024-03-21 20:19:40 +0200 | |
commit | 92b584912b5accf876df16b72cbc73af1c550591 (patch) | |
tree | f1441495630f530d69762359dd95db3539cc6e1e | |
parent | db connection: use better dial timeout instead of just sleep (diff) | |
download | soko-92b584912b5accf876df16b72cbc73af1c550591.tar.gz soko-92b584912b5accf876df16b72cbc73af1c550591.tar.bz2 soko-92b584912b5accf876df16b72cbc73af1c550591.zip |
db connection: cleanup TruncateTable function
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | pkg/database/connection.go | 4 | ||||
-rw-r--r-- | pkg/portage/bugs/bugs.go | 6 | ||||
-rw-r--r-- | pkg/portage/dependencies/dependency.go | 2 | ||||
-rw-r--r-- | pkg/portage/github/pullrequests.go | 4 | ||||
-rw-r--r-- | pkg/portage/maintainers/update.go | 2 | ||||
-rw-r--r-- | pkg/portage/pkgcheck/parse.go | 2 | ||||
-rw-r--r-- | pkg/portage/projects/update.go | 4 | ||||
-rw-r--r-- | pkg/portage/repology/outdated.go | 2 | ||||
-rw-r--r-- | pkg/portage/repository/deprecated.go | 4 | ||||
-rw-r--r-- | pkg/portage/repository/mask.go | 4 | ||||
-rw-r--r-- | pkg/portage/update.go | 2 |
11 files changed, 18 insertions, 18 deletions
diff --git a/pkg/database/connection.go b/pkg/database/connection.go index e698622..77a6b50 100644 --- a/pkg/database/connection.go +++ b/pkg/database/connection.go @@ -105,8 +105,8 @@ func Connect() { } } -func TruncateTable[K any](_ string) { - query := DBCon.Model((*K)(nil)) +func TruncateTable(model any) { + query := DBCon.Model(model) tableName := string(query.TableModel().Table().TypeName) _, err := query.Exec("TRUNCATE TABLE ?TableName") if err != nil { diff --git a/pkg/portage/bugs/bugs.go b/pkg/portage/bugs/bugs.go index 3887803..3e803b8 100644 --- a/pkg/portage/bugs/bugs.go +++ b/pkg/portage/bugs/bugs.go @@ -133,9 +133,9 @@ func importAllOpenBugs() { return } - database.TruncateTable[models.Bug]("id") - database.TruncateTable[models.PackageToBug]("id") - database.TruncateTable[models.VersionToBug]("id") + database.TruncateTable((*models.Bug)(nil)) + database.TruncateTable((*models.PackageToBug)(nil)) + database.TruncateTable((*models.VersionToBug)(nil)) processApiBugs(bugs) } diff --git a/pkg/portage/dependencies/dependency.go b/pkg/portage/dependencies/dependency.go index 6530802..e6e4358 100644 --- a/pkg/portage/dependencies/dependency.go +++ b/pkg/portage/dependencies/dependency.go @@ -29,7 +29,7 @@ func FullPackageDependenciesUpdate() { slog.Info("collected dependencies", slog.Int("count", dependencyCounter)) - database.TruncateTable[models.ReverseDependency]("id") + database.TruncateTable((*models.ReverseDependency)(nil)) // because we removed all previous rows in table, we aren't concerned about // duplicates, so we can use bulk insert res, err := database.DBCon.Model(&Dependencies).Insert() diff --git a/pkg/portage/github/pullrequests.go b/pkg/portage/github/pullrequests.go index 71748ec..9399a06 100644 --- a/pkg/portage/github/pullrequests.go +++ b/pkg/portage/github/pullrequests.go @@ -108,8 +108,8 @@ func FullUpdatePullRequests() { database.Connect() defer database.DBCon.Close() - database.TruncateTable[models.GithubPullRequest]("id") - database.TruncateTable[models.PackageToGithubPullRequest]("id") + database.TruncateTable((*models.GithubPullRequest)(nil)) + database.TruncateTable((*models.PackageToGithubPullRequest)(nil)) // year of the git migration updatePullRequestsAfter(true, "2015-01-01", "") diff --git a/pkg/portage/maintainers/update.go b/pkg/portage/maintainers/update.go index 46aaf32..306d9d8 100644 --- a/pkg/portage/maintainers/update.go +++ b/pkg/portage/maintainers/update.go @@ -117,7 +117,7 @@ func FullImport() { // TODO in future we want an incremental update here // but for now we delete everything and insert it again // this is currently acceptable as it takes less than 2 seconds - database.TruncateTable[models.Maintainer]("email") + database.TruncateTable((*models.Maintainer)(nil)) rows := make([]*models.Maintainer, 0, len(maintainers)) for _, row := range maintainers { diff --git a/pkg/portage/pkgcheck/parse.go b/pkg/portage/pkgcheck/parse.go index ae7a3d2..6eab781 100644 --- a/pkg/portage/pkgcheck/parse.go +++ b/pkg/portage/pkgcheck/parse.go @@ -56,7 +56,7 @@ func UpdatePkgCheckResults() { } // clean up the database - database.TruncateTable[models.PkgCheckResult]("id") + database.TruncateTable((*models.PkgCheckResult)(nil)) // update the database with the new results rows := make([]*models.PkgCheckResult, 0, len(collected)) diff --git a/pkg/portage/projects/update.go b/pkg/portage/projects/update.go index 30fe7a8..d463862 100644 --- a/pkg/portage/projects/update.go +++ b/pkg/portage/projects/update.go @@ -40,8 +40,8 @@ func UpdateProjects() { } // clean up the database - database.TruncateTable[models.Project]("email") - database.TruncateTable[models.MaintainerToProject]("id") + database.TruncateTable((*models.Project)(nil)) + database.TruncateTable((*models.MaintainerToProject)(nil)) // insert new project list _, err = database.DBCon.Model(&projectList).Insert() diff --git a/pkg/portage/repology/outdated.go b/pkg/portage/repology/outdated.go index aa8b6c9..93f9008 100644 --- a/pkg/portage/repology/outdated.go +++ b/pkg/portage/repology/outdated.go @@ -43,7 +43,7 @@ func UpdateOutdated() { // Update the database if len(outdated.outdatedVersions) > 0 { - database.TruncateTable[models.OutdatedPackages]("atom") + database.TruncateTable((*models.OutdatedPackages)(nil)) res, err := database.DBCon.Model(&outdated.outdatedVersions).Insert() if err != nil { diff --git a/pkg/portage/repository/deprecated.go b/pkg/portage/repository/deprecated.go index 689faa4..594c553 100644 --- a/pkg/portage/repository/deprecated.go +++ b/pkg/portage/repository/deprecated.go @@ -52,7 +52,7 @@ func UpdatePackagesDeprecated(path string) { // delete all existing entries before parsing the file again // in future we might implement a incremental version here - database.TruncateTable[models.DeprecatedPackage]("versions") + database.TruncateTable((*models.DeprecatedPackage)(nil)) for _, entry := range getDeprecatedPackages(changedFile) { parsePackagesDeprecated(entry) @@ -124,7 +124,7 @@ func getDeprecatedPackages(path string) []string { // Calculate all versions that are currently // deprecated and update the DeprecatedToVersion Table func CalculateDeprecatedToVersion() { - database.TruncateTable[models.DeprecatedToVersion]("id") + database.TruncateTable((*models.DeprecatedToVersion)(nil)) var deprecates []*models.DeprecatedPackage err := database.DBCon.Model(&deprecates).Select() diff --git a/pkg/portage/repository/mask.go b/pkg/portage/repository/mask.go index 6101fd8..c6b500c 100644 --- a/pkg/portage/repository/mask.go +++ b/pkg/portage/repository/mask.go @@ -56,7 +56,7 @@ func UpdateMask(path string) { // delete all existing masks before parsing the file again // in future we might implement a incremental version here - database.TruncateTable[models.Mask]("versions") + database.TruncateTable((*models.Mask)(nil)) for _, packageMask := range getMasks(changedFile) { parsePackageMask(packageMask) @@ -170,7 +170,7 @@ func getMasks(path string) []string { // masked and update the MaskToVersion Table func CalculateMaskedVersions() { // clean up all masked versions before recalculating them - database.TruncateTable[models.MaskToVersion]("id") + database.TruncateTable((*models.MaskToVersion)(nil)) var masks []*models.Mask err := database.DBCon.Model(&masks).Select() diff --git a/pkg/portage/update.go b/pkg/portage/update.go index 394cce3..8ad9187 100644 --- a/pkg/portage/update.go +++ b/pkg/portage/update.go @@ -127,7 +127,7 @@ func FullUpdate() { slog.Info("Update all present files") // update useflags - database.TruncateTable[models.Useflag]("id") + database.TruncateTable((*models.Useflag)(nil)) repository.UpdateUse("profiles/use.desc") repository.UpdateUse("profiles/use.local.desc") if entries, err := os.ReadDir(config.PortDir() + "/profiles/desc"); err != nil { |