added prefixses to db keys

This commit is contained in:
Radu Ioan Fericean
2012-08-17 17:36:42 +03:00
parent df86338b0c
commit 1d4911f42a
6 changed files with 34 additions and 28 deletions

View File

@@ -111,7 +111,7 @@ func (csvr *CSVReader) WriteToDatabase(storage StorageGetter, flush, verbose boo
log.Print("Action timings")
}
for k, ats := range csvr.actionsTimings {
err = storage.SetActionTimings(ACTION_TIMING_PREFIX+k, ats)
err = storage.SetActionTimings(k, ats)
if err != nil {
return err
}

View File

@@ -29,7 +29,7 @@ const (
)
type RatingProfile struct {
Id string `bson:"_id,omitempty"`
Id string
FallbackKey string
DestinationMap map[string][]*ActivationPeriod
}

View File

@@ -26,9 +26,14 @@ import (
)
const (
ACTION_TIMING_PREFIX = "acttmg:"
CALL_COST_LOG_PREFIX = "cc:"
LOG_PREFIX = "log:"
ACTION_TIMING_PREFIX = "acttmg_"
CALL_COST_LOG_PREFIX = "cc_"
LOG_PREFIX = "log_"
RATING_PROFILE_PREFIX = "ratingprofile_"
ACTION_PREFIX = "action_"
USER_BALANCE_PREFIX = "userbalance_"
DESTINATION_PREFIX = "dest_"
ACTION_TIMING = "actiontiming_"
)
/*

View File

@@ -42,7 +42,7 @@ func (ms *MapStorage) Flush() error {
}
func (ms *MapStorage) GetRatingProfile(key string) (rp *RatingProfile, err error) {
if values, ok := ms.dict[key]; ok {
if values, ok := ms.dict[RATING_PROFILE_PREFIX+key]; ok {
rp = new(RatingProfile)
err = ms.ms.Unmarshal(values, rp)
} else {
@@ -53,12 +53,12 @@ func (ms *MapStorage) GetRatingProfile(key string) (rp *RatingProfile, err error
func (ms *MapStorage) SetRatingProfile(rp *RatingProfile) (err error) {
result, err := ms.ms.Marshal(rp)
ms.dict[rp.Id] = result
ms.dict[RATING_PROFILE_PREFIX+rp.Id] = result
return
}
func (ms *MapStorage) GetDestination(key string) (dest *Destination, err error) {
if values, ok := ms.dict[key]; ok {
if values, ok := ms.dict[DESTINATION_PREFIX+key]; ok {
dest = &Destination{Id: key}
err = ms.ms.Unmarshal(values, dest)
} else {
@@ -68,12 +68,12 @@ func (ms *MapStorage) GetDestination(key string) (dest *Destination, err error)
}
func (ms *MapStorage) SetDestination(dest *Destination) (err error) {
result, err := ms.ms.Marshal(dest)
ms.dict[dest.Id] = result
ms.dict[DESTINATION_PREFIX+dest.Id] = result
return
}
func (ms *MapStorage) GetActions(key string) (as []*Action, err error) {
if values, ok := ms.dict[key]; ok {
if values, ok := ms.dict[ACTION_PREFIX+key]; ok {
err = ms.ms.Unmarshal(values, &as)
} else {
return nil, errors.New("not found")
@@ -83,12 +83,12 @@ func (ms *MapStorage) GetActions(key string) (as []*Action, err error) {
func (ms *MapStorage) SetActions(key string, as []*Action) (err error) {
result, err := ms.ms.Marshal(as)
ms.dict[key] = result
ms.dict[ACTION_PREFIX+key] = result
return
}
func (ms *MapStorage) GetUserBalance(key string) (ub *UserBalance, err error) {
if values, ok := ms.dict[key]; ok {
if values, ok := ms.dict[USER_BALANCE_PREFIX+key]; ok {
ub = &UserBalance{Id: key}
err = ms.ms.Unmarshal(values, ub)
} else {
@@ -99,12 +99,12 @@ func (ms *MapStorage) GetUserBalance(key string) (ub *UserBalance, err error) {
func (ms *MapStorage) SetUserBalance(ub *UserBalance) (err error) {
result, err := ms.ms.Marshal(ub)
ms.dict[ub.Id] = result
ms.dict[USER_BALANCE_PREFIX+ub.Id] = result
return
}
func (ms *MapStorage) GetActionTimings(key string) (ats []*ActionTiming, err error) {
if values, ok := ms.dict[key]; ok {
if values, ok := ms.dict[ACTION_TIMING_PREFIX+key]; ok {
err = ms.ms.Unmarshal(values, &ats)
} else {
return nil, errors.New("not found")
@@ -115,11 +115,11 @@ func (ms *MapStorage) GetActionTimings(key string) (ats []*ActionTiming, err err
func (ms *MapStorage) SetActionTimings(key string, ats []*ActionTiming) (err error) {
if len(ats) == 0 {
// delete the key
delete(ms.dict, key)
delete(ms.dict, ACTION_TIMING_PREFIX+key)
return
}
result, err := ms.ms.Marshal(ats)
ms.dict[key] = result
ms.dict[ACTION_TIMING_PREFIX+key] = result
return
}

View File

@@ -49,6 +49,7 @@ func NewMongoStorage(host, port, db, user, pass string) (StorageGetter, error) {
err = ndb.C("actions").EnsureIndex(index)
err = ndb.C("actiontimings").EnsureIndex(index)
index = mgo.Index{Key: []string{"id"}, Background: true}
err = ndb.C("ratingprofiles").EnsureIndex(index)
err = ndb.C("destinations").EnsureIndex(index)
err = ndb.C("userbalances").EnsureIndex(index)
@@ -166,7 +167,7 @@ func (ms *MongoStorage) SetActionTimings(key string, ats []*ActionTiming) error
func (ms *MongoStorage) GetAllActionTimings() (ats map[string][]*ActionTiming, err error) {
result := AtKeyValue{}
iter := ms.db.C("actiontimings").Find(bson.M{"key": fmt.Sprintf("/^%s/", ACTION_TIMING_PREFIX)}).Iter()
iter := ms.db.C("actiontimings").Find(nil).Iter()
ats = make(map[string][]*ActionTiming)
for iter.Next(&result) {
ats[result.Key] = result.Value

View File

@@ -48,7 +48,7 @@ func (rs *RedisStorage) Flush() error {
}
func (rs *RedisStorage) GetRatingProfile(key string) (rp *RatingProfile, err error) {
if values, err := rs.db.Get(key); err == nil {
if values, err := rs.db.Get(RATING_PROFILE_PREFIX + key); err == nil {
rp = new(RatingProfile)
err = rs.ms.Unmarshal(values, rp)
} else {
@@ -59,11 +59,11 @@ func (rs *RedisStorage) GetRatingProfile(key string) (rp *RatingProfile, err err
func (rs *RedisStorage) SetRatingProfile(rp *RatingProfile) (err error) {
result, err := rs.ms.Marshal(rp)
return rs.db.Set(rp.Id, result)
return rs.db.Set(RATING_PROFILE_PREFIX+rp.Id, result)
}
func (rs *RedisStorage) GetDestination(key string) (dest *Destination, err error) {
if values, err := rs.db.Get(key); err == nil {
if values, err := rs.db.Get(DESTINATION_PREFIX + key); err == nil {
dest = &Destination{Id: key}
err = rs.ms.Unmarshal(values, dest)
} else {
@@ -74,11 +74,11 @@ func (rs *RedisStorage) GetDestination(key string) (dest *Destination, err error
func (rs *RedisStorage) SetDestination(dest *Destination) (err error) {
result, err := rs.ms.Marshal(dest)
return rs.db.Set(dest.Id, result)
return rs.db.Set(DESTINATION_PREFIX+dest.Id, result)
}
func (rs *RedisStorage) GetActions(key string) (as []*Action, err error) {
if values, err := rs.db.Get(key); err == nil {
if values, err := rs.db.Get(ACTION_PREFIX + key); err == nil {
err = rs.ms.Unmarshal(values, &as)
} else {
return nil, err
@@ -88,11 +88,11 @@ func (rs *RedisStorage) GetActions(key string) (as []*Action, err error) {
func (rs *RedisStorage) SetActions(key string, as []*Action) (err error) {
result, err := rs.ms.Marshal(as)
return rs.db.Set(key, result)
return rs.db.Set(ACTION_PREFIX+key, result)
}
func (rs *RedisStorage) GetUserBalance(key string) (ub *UserBalance, err error) {
if values, err := rs.db.Get(key); err == nil {
if values, err := rs.db.Get(USER_BALANCE_PREFIX+key); err == nil {
ub = &UserBalance{Id: key}
err = rs.ms.Unmarshal(values, ub)
} else {
@@ -103,11 +103,11 @@ func (rs *RedisStorage) GetUserBalance(key string) (ub *UserBalance, err error)
func (rs *RedisStorage) SetUserBalance(ub *UserBalance) (err error) {
result, err := rs.ms.Marshal(ub)
return rs.db.Set(ub.Id, result)
return rs.db.Set(USER_BALANCE_PREFIX+ub.Id, result)
}
func (rs *RedisStorage) GetActionTimings(key string) (ats []*ActionTiming, err error) {
if values, err := rs.db.Get(key); err == nil {
if values, err := rs.db.Get(ACTION_TIMING_PREFIX + key); err == nil {
err = rs.ms.Unmarshal(values, &ats)
} else {
return nil, err
@@ -118,11 +118,11 @@ func (rs *RedisStorage) GetActionTimings(key string) (ats []*ActionTiming, err e
func (rs *RedisStorage) SetActionTimings(key string, ats []*ActionTiming) (err error) {
if len(ats) == 0 {
// delete the key
_, err = rs.db.Del(key)
_, err = rs.db.Del(ACTION_TIMING_PREFIX + key)
return
}
result, err := rs.ms.Marshal(ats)
return rs.db.Set(key, result)
return rs.db.Set(ACTION_TIMING_PREFIX+key, result)
}
func (rs *RedisStorage) GetAllActionTimings() (ats map[string][]*ActionTiming, err error) {