Introduced CountAll for repositories
This commit is contained in:
@@ -6,7 +6,11 @@ type BaseRepository struct {
|
|||||||
|
|
||||||
|
|
||||||
func (r *BaseRepository) saveOrUpdate(id string, rec interface{}) error {
|
func (r *BaseRepository) saveOrUpdate(id string, rec interface{}) error {
|
||||||
return saveStruct(r.key + "_id_" + id, rec)
|
return saveStruct(r.key, id, rec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *BaseRepository) CountAll() (int, error) {
|
||||||
|
return count(r.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *BaseRepository) Dump() {
|
func (r *BaseRepository) Dump() {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func db() *ledis.DB {
|
|||||||
return _dbInstance
|
return _dbInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveStruct(key string, data interface{}) error {
|
func saveStruct(key, id string, data interface{}) error {
|
||||||
h, err := utils.ToMap(data)
|
h, err := utils.ToMap(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -40,7 +40,10 @@ func saveStruct(key string, data interface{}) error {
|
|||||||
fvList[i].Value, _ = json.Marshal(v)
|
fvList[i].Value, _ = json.Marshal(v)
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
return db().HMset([]byte(key), fvList...)
|
kh := key + "_id_" + id
|
||||||
|
ks := key + "_ids"
|
||||||
|
db().SAdd([]byte(ks), []byte(id))
|
||||||
|
return db().HMset([]byte(kh), fvList...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readStruct(key string) (interface{}, error) {
|
func readStruct(key string) (interface{}, error) {
|
||||||
@@ -55,6 +58,11 @@ func readStruct(key string) (interface{}, error) {
|
|||||||
return utils.ToStruct(m)
|
return utils.ToStruct(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func count(key string) (int, error) {
|
||||||
|
ids, err := db().SMembers([]byte(key + "_ids"))
|
||||||
|
return len(ids), err
|
||||||
|
}
|
||||||
|
|
||||||
func hset(key, field, value string) error {
|
func hset(key, field, value string) error {
|
||||||
_, err := db().HSet([]byte(key), []byte(field), []byte(value))
|
_, err := db().HSet([]byte(key), []byte(field), []byte(value))
|
||||||
return err
|
return err
|
||||||
|
|||||||
+4
-4
@@ -5,8 +5,6 @@ import (
|
|||||||
"github.com/deluan/gosonic/repositories"
|
"github.com/deluan/gosonic/repositories"
|
||||||
"github.com/deluan/gosonic/models"
|
"github.com/deluan/gosonic/models"
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
|
||||||
"encoding/json"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Scanner interface {
|
type Scanner interface {
|
||||||
@@ -46,8 +44,10 @@ func updateDatastore(files []Track) {
|
|||||||
collectIndex(m, artistIndex)
|
collectIndex(m, artistIndex)
|
||||||
}
|
}
|
||||||
//mfRepo.Dump()
|
//mfRepo.Dump()
|
||||||
j,_ := json.MarshalIndent(artistIndex, "", " ")
|
//j,_ := json.MarshalIndent(artistIndex, "", " ")
|
||||||
fmt.Println(string(j))
|
//fmt.Println(string(j))
|
||||||
|
c, _ := mfRepo.CountAll()
|
||||||
|
beego.Info("Total mediafiles in database:", c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectIndex(m *models.MediaFile, artistIndex map[string]map[string]string) {
|
func collectIndex(m *models.MediaFile, artistIndex map[string]map[string]string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user