Skip to content

Commit

Permalink
refactor(db): Rename Get -> CacheGet, Upsert -> CachePut
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbinoGeek committed May 20, 2024
1 parent 06401d9 commit d7400ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/flower/searchCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/db/DB_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
Expand Down
8 changes: 4 additions & 4 deletions pkg/db/PluginRegistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d7400ce

Please sign in to comment.