Skip to content

Commit

Permalink
update producer/docstore/docstore.go to check existing value and skip…
Browse files Browse the repository at this point in the history
… if it is the same as a the (new) value to set
  • Loading branch information
thisisaaronland committed Sep 10, 2022
1 parent b09ce41 commit a96aee5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion producer/docstore/docstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,27 @@ type CatalogRecord struct {

func AddToCatalog(ctx context.Context, collection *gc_docstore.Collection, id int64, repo_name string) error {

test_doc := map[string]interface{}{
"id": id,
"repo_name": "",
}

err := collection.Get(ctx, test_doc)

if err != nil {
return fmt.Errorf("Failed to get record for %d, %w", id, err)
}

if test_doc["repo_name"] == repo_name {
return nil
}

doc := &CatalogRecord{
Id: id,
RepoName: repo_name,
}

err := collection.Put(ctx, doc)
err = collection.Put(ctx, doc)

if err != nil {
return fmt.Errorf("Failed to put catalog record for %d, %w", id, err)
Expand Down

0 comments on commit a96aee5

Please sign in to comment.