cleanUp: use tx.Get for getting values from DB

tx.AscendKeys can be used for collecting multiple keys, values.
In our case we only collect one key, value therefore use tx.Get
This commit is contained in:
Miltiadis Kallianis 2022-09-02 13:18:58 +02:00
parent 446865a19c
commit 219695f795

View file

@ -1,14 +1,15 @@
package z package z
import ( import (
"encoding/json"
"errors"
"log"
"os" "os"
"sort" "sort"
"strings" "strings"
"log"
"errors"
"encoding/json"
"github.com/tidwall/buntdb"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/tidwall/buntdb"
) )
type Database struct { type Database struct {
@ -71,14 +72,13 @@ func (database *Database) GetEntry(user string, entryId string) (Entry, error) {
var entry Entry var entry Entry
dberr := database.DB.View(func(tx *buntdb.Tx) error { dberr := database.DB.View(func(tx *buntdb.Tx) error {
tx.AscendKeys(user + ":entry:" + entryId, func(key, value string) bool { value, err := tx.Get(user + ":entry:" + entryId)
if err != nil {
return err
}
json.Unmarshal([]byte(value), &entry) json.Unmarshal([]byte(value), &entry)
entry.SetIDFromDatabaseKey(key) entry.ID = entryId
return true
})
return nil return nil
}) })
@ -164,11 +164,11 @@ func (database *Database) GetRunningEntryId(user string) (string, error) {
var runningId string = "" var runningId string = ""
dberr := database.DB.View(func(tx *buntdb.Tx) error { dberr := database.DB.View(func(tx *buntdb.Tx) error {
tx.AscendKeys(user + ":status:running", func(key, value string) bool { value, err := tx.Get(user + ":status:running")
if err != nil {
return err
}
runningId = value runningId = value
return true
})
return nil return nil
}) })