Skip to content

Commit

Permalink
Merge pull request #38 from beclab/fix/local-app-data
Browse files Browse the repository at this point in the history
fix: local app data
  • Loading branch information
icebergtsn authored Sep 25, 2024
2 parents 776e6f1 + c57a4a4 commit 0e15b77
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions internal/boltdb/local_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package boltdb
import (
"encoding/json"
"fmt"
"github.com/boltdb/bolt"
"github.com/golang/glog"
"market/internal/conf"
"market/internal/models"

"github.com/boltdb/bolt"
"github.com/golang/glog"
)

func UpsertLocalAppInfo(info *models.ApplicationInfo) error {
Expand Down Expand Up @@ -178,28 +179,56 @@ func GetLocalAppInfos(keys []string) []*models.ApplicationInfo {

func GetLocalAppInfoMap() (appMap map[string]*models.ApplicationInfo, err error) {
appMap = make(map[string]*models.ApplicationInfo)
glog.Infof("Initializing GetLocalAppInfoMap")

if bdbClient == nil {
glog.Infof("bdbClient is nil")
return
}

if bdbClient.bdb == nil {
glog.Infof("bdbClient.bdb is nil")
return
}

err = bdbClient.bdb.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte(LocalDevAppsBucketName))
if bucket == nil {
glog.Warningf("bucket %s not found", LocalDevAppsBucketName)
return fmt.Errorf("bucket %s not found", LocalDevAppsBucketName)
}

glog.Infof("Successfully retrieved bucket: %s", LocalDevAppsBucketName)

cursor := bucket.Cursor()
for k, v := cursor.First(); k != nil; k, v = cursor.Next() {
glog.Infof("Key: %s, Value: %s\n", k, v)

info := &models.ApplicationInfo{}
err = json.Unmarshal(v, info)
if err != nil {
glog.Errorf("Failed to unmarshal value for key %s: %v", k, err)
continue
}

if info.Name == "" {
glog.Warningf("ApplicationInfo for key %s has empty Name field", k)
continue
}

appMap[info.Name] = info
glog.Infof("Added ApplicationInfo to map: %s", info.Name)
}

glog.Infof("Finished processing bucket: %s", LocalDevAppsBucketName)
return nil
})

if err != nil {
glog.Errorf("Error during GetLocalAppInfoMap: %v", err)
} else {
glog.Infof("Successfully retrieved application info map with %d entries", len(appMap))
}

return
}

0 comments on commit 0e15b77

Please sign in to comment.