From d7400ce1827c5ec08f6d021cfc69456d02925990 Mon Sep 17 00:00:00 2001 From: Damon Blais Date: Mon, 20 May 2024 03:33:18 -0700 Subject: [PATCH] refactor(db): Rename Get -> CacheGet, Upsert -> CachePut --- cmd/flower/searchCmd.go | 4 ++-- pkg/db/DB_test.go | 8 ++++---- pkg/db/PluginRegistry.go | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/flower/searchCmd.go b/cmd/flower/searchCmd.go index be5fed1..4aa801a 100644 --- a/cmd/flower/searchCmd.go +++ b/cmd/flower/searchCmd.go @@ -54,7 +54,7 @@ func searchPlugin(ctx context.Context, query string) error { // Update our cache records := make([]*types.PluginCacheRecord, 0) for _, repo := range repos.Repositories { - cacheRecord, err := DB.Plugins.Get(*repo.FullName) + cacheRecord, err := DB.Plugins.CacheGet(*repo.FullName) if err != nil || cacheRecord == nil { // We have never encountered this repo before, we must interrogate it analysis, err := githubRepoAnalyze(ctx, *repo.FullName) @@ -91,7 +91,7 @@ func searchPlugin(ctx context.Context, query string) error { cacheRecord.Summary = *repo.Description cacheRecord.Tags = strings.Join(repo.Topics, ",") - if err := DB.Plugins.Upsert(cacheRecord); err != nil { + if err := DB.Plugins.CachePut(cacheRecord); err != nil { return err } diff --git a/pkg/db/DB_test.go b/pkg/db/DB_test.go index e0a8335..9ad3282 100644 --- a/pkg/db/DB_test.go +++ b/pkg/db/DB_test.go @@ -36,19 +36,19 @@ func TestPluginRegistry(t *testing.T) { Summary: "A test plugin", } - err = db.Plugins.Upsert(plugin) + err = db.Plugins.CachePut(plugin) convey.So(err, convey.ShouldBeNil) - actualPlugin, err := db.Plugins.Get(plugin.ID) + actualPlugin, err := db.Plugins.CacheGet(plugin.ID) convey.So(err, convey.ShouldBeNil) convey.So(actualPlugin, convey.ShouldResemble, plugin) convey.Convey("And when the plugin is updated", func() { plugin.Name = "Updated Plugin" - err = db.Plugins.Upsert(plugin) + err = db.Plugins.CachePut(plugin) convey.So(err, convey.ShouldBeNil) - actualPlugin, err := db.Plugins.Get(plugin.ID) + actualPlugin, err := db.Plugins.CacheGet(plugin.ID) convey.So(err, convey.ShouldBeNil) convey.So(actualPlugin.Name, convey.ShouldEqual, "Updated Plugin") }) diff --git a/pkg/db/PluginRegistry.go b/pkg/db/PluginRegistry.go index d885a11..3d7d9de 100644 --- a/pkg/db/PluginRegistry.go +++ b/pkg/db/PluginRegistry.go @@ -6,8 +6,8 @@ import ( ) type IPluginRegistry interface { - Get(id string) (*types.PluginCacheRecord, error) - Upsert(record *types.PluginCacheRecord) error + CacheGet(id string) (*types.PluginCacheRecord, error) + CachePut(record *types.PluginCacheRecord) error } // Ensure PluginRegistry implements IPluginRegistry @@ -23,7 +23,7 @@ const UPSERT_PLUGIN_CACHE = `INSERT OR REPLACE INTO plugin_cache ( id, updated_at, name, version, author, license, bugs_url, homepage, api_version, tags, summary ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` -func (r *PluginRegistry) Get(id string) (*types.PluginCacheRecord, error) { +func (r *PluginRegistry) CacheGet(id string) (*types.PluginCacheRecord, error) { r.log.Debug("searching for plugin", "id", id) stmt, err := r.db.conn.Prepare(SELECT_PLUGIN_CACHE) @@ -36,7 +36,7 @@ func (r *PluginRegistry) Get(id string) (*types.PluginCacheRecord, error) { return record, stmt.QueryRow(id).Scan(&record.ID, &record.UpdatedAt, &record.Name, &record.Version, &record.Author, &record.License, &record.BugsURL, &record.Homepage, &record.APIVersion, &record.Tags, &record.Summary) } -func (reg *PluginRegistry) Upsert(record *types.PluginCacheRecord) error { +func (reg *PluginRegistry) CachePut(record *types.PluginCacheRecord) error { reg.log.Debug("upserting plugin", "id", record.ID) stmt, err := reg.db.conn.Prepare(UPSERT_PLUGIN_CACHE)