From 0f32d7ec0de3f5f81efa2e84e3e4dccc238146a7 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 18 Sep 2024 14:46:52 -0600 Subject: [PATCH] Changed DeleteScannedAssets to work correct and added db tag --- internal/cache/sqlite/sqlite.go | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/internal/cache/sqlite/sqlite.go b/internal/cache/sqlite/sqlite.go index e3a6bc7..bbbdff3 100644 --- a/internal/cache/sqlite/sqlite.go +++ b/internal/cache/sqlite/sqlite.go @@ -2,7 +2,6 @@ package sqlite import ( "fmt" - "strings" "github.com/davidallendj/magellan/internal/util" magellan "github.com/davidallendj/magellan/pkg" @@ -78,22 +77,7 @@ func DeleteScannedAssets(path string, assets ...magellan.RemoteAsset) error { } tx = db.MustBegin() for _, asset := range assets { - // skip if neither host nor port are specified - if asset.Host == "" && asset.Port <= 0 { - continue - } - sql := fmt.Sprintf(`DELETE FROM %s`, TABLE_NAME) - where := []string{} - if asset.Port > 0 { - where = append(where, "port=:port") - } - if asset.Host != "" { - where = append(where, "host=:host") - } - if len(where) <= 0 { - continue - } - sql += fmt.Sprintf(" WHERE %s;", strings.Join(where, " AND ")) + sql := fmt.Sprintf(`DELETE FROM %s WHERE host=:host AND port=:port;`, TABLE_NAME) _, err := tx.NamedExec(sql, &asset) if err != nil { fmt.Printf("failed to execute DELETE transaction: %v\n", err)