mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Replaced map[string]struct{} with utils.StringSet
This commit is contained in:
committed by
Dan Christian Bogos
parent
e56d86de98
commit
1c9bd9d4f2
@@ -154,7 +154,7 @@ func appendDNSAnswer(msg *dns.Msg) (err error) {
|
||||
|
||||
// updateDNSMsgFromNM will update DNS message with values from NavigableMap
|
||||
func updateDNSMsgFromNM(msg *dns.Msg, nm *utils.OrderedNavigableMap) (err error) {
|
||||
msgFields := make(map[string]struct{}) // work around to NMap issue
|
||||
msgFields := make(utils.StringSet) // work around to NMap issue
|
||||
for el := nm.GetFirstElement(); el != nil; el = el.Next() {
|
||||
val := el.Value
|
||||
var nmIt utils.NMInterface
|
||||
@@ -169,14 +169,14 @@ func updateDNSMsgFromNM(msg *dns.Msg, nm *utils.OrderedNavigableMap) (err error)
|
||||
return errors.New("empty path in config item")
|
||||
}
|
||||
apnd := len(msg.Answer) == 0
|
||||
if _, has := msgFields[cfgItm.Path[0]]; has { // force append if the same path was already used
|
||||
if msgFields.Has(cfgItm.Path[0]) { // force append if the same path was already used
|
||||
apnd = true
|
||||
}
|
||||
if apnd {
|
||||
if err = appendDNSAnswer(msg); err != nil {
|
||||
return
|
||||
}
|
||||
msgFields = make(map[string]struct{}) // reset the fields inside since we have a new message
|
||||
msgFields = make(utils.StringSet) // reset the fields inside since we have a new message
|
||||
}
|
||||
itmData := cfgItm.Data
|
||||
switch cfgItm.Path[0] {
|
||||
@@ -226,7 +226,7 @@ func updateDNSMsgFromNM(msg *dns.Msg, nm *utils.OrderedNavigableMap) (err error)
|
||||
msg.Answer[len(msg.Answer)-1].(*dns.NAPTR).Replacement = utils.IfaceAsString(itmData)
|
||||
}
|
||||
|
||||
msgFields[cfgItm.Path[0]] = struct{}{} // detect new branch
|
||||
msgFields.Add(cfgItm.Path[0]) // detect new branch
|
||||
|
||||
}
|
||||
return
|
||||
|
||||
@@ -66,7 +66,7 @@ func (self *CmdGetAccounts) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdGetAccounts) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedSliceResult(result, map[string]struct{}{
|
||||
return GetFormatedSliceResult(result, utils.StringSet{
|
||||
"MinSleep": {},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (self *CmdActiveSessions) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdActiveSessions) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedSliceResult(result, map[string]struct{}{
|
||||
return GetFormatedSliceResult(result, utils.StringSet{
|
||||
"Usage": {},
|
||||
"DurationIndex": {},
|
||||
"MaxRateUnit": {},
|
||||
|
||||
@@ -75,7 +75,7 @@ func (self *CmdAttributesProcessEvent) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdAttributesProcessEvent) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"Usage": {},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func (self *CmdChargersProcessEvent) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdChargersProcessEvent) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"Usage": {},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ func FromJSON(jsn []byte, interestingFields []string) (line string) {
|
||||
return strings.TrimSpace(line)
|
||||
}
|
||||
|
||||
func getStringValue(v interface{}, defaultDurationFields map[string]struct{}) string {
|
||||
func getStringValue(v interface{}, defaultDurationFields utils.StringSet) string {
|
||||
switch o := v.(type) {
|
||||
case nil:
|
||||
return "null"
|
||||
@@ -154,7 +154,7 @@ func getStringValue(v interface{}, defaultDurationFields map[string]struct{}) st
|
||||
return utils.ToJSON(v)
|
||||
}
|
||||
|
||||
func getSliceAsString(mp []interface{}, defaultDurationFields map[string]struct{}) (out string) {
|
||||
func getSliceAsString(mp []interface{}, defaultDurationFields utils.StringSet) (out string) {
|
||||
out = "["
|
||||
for _, v := range mp {
|
||||
out += fmt.Sprintf(`%s,`, getStringValue(v, defaultDurationFields))
|
||||
@@ -162,11 +162,11 @@ func getSliceAsString(mp []interface{}, defaultDurationFields map[string]struct{
|
||||
return strings.TrimSuffix(out, ",") + "]"
|
||||
}
|
||||
|
||||
func getMapAsString(mp map[string]interface{}, defaultDurationFields map[string]struct{}) (out string) {
|
||||
func getMapAsString(mp map[string]interface{}, defaultDurationFields utils.StringSet) (out string) {
|
||||
// in order to find the data faster
|
||||
keylist := []string{} // add key value pairs to list so at the end we can sort them
|
||||
for k, v := range mp {
|
||||
if _, has := defaultDurationFields[k]; has {
|
||||
if defaultDurationFields.Has(k) {
|
||||
if t, err := utils.IfaceAsDuration(v); err == nil {
|
||||
keylist = append(keylist, fmt.Sprintf(`"%s":"%s"`, k, t.String()))
|
||||
continue
|
||||
@@ -178,7 +178,7 @@ func getMapAsString(mp map[string]interface{}, defaultDurationFields map[string]
|
||||
return fmt.Sprintf(`{%s}`, strings.Join(keylist, ","))
|
||||
}
|
||||
|
||||
func GetFormatedResult(result interface{}, defaultDurationFields map[string]struct{}) string {
|
||||
func GetFormatedResult(result interface{}, defaultDurationFields utils.StringSet) string {
|
||||
jsonResult, _ := json.Marshal(result)
|
||||
var mp map[string]interface{}
|
||||
if err := json.Unmarshal(jsonResult, &mp); err != nil {
|
||||
@@ -191,7 +191,7 @@ func GetFormatedResult(result interface{}, defaultDurationFields map[string]stru
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func GetFormatedSliceResult(result interface{}, defaultDurationFields map[string]struct{}) string {
|
||||
func GetFormatedSliceResult(result interface{}, defaultDurationFields utils.StringSet) string {
|
||||
jsonResult, _ := json.Marshal(result)
|
||||
var mp []interface{}
|
||||
if err := json.Unmarshal(jsonResult, &mp); err != nil {
|
||||
|
||||
@@ -110,7 +110,7 @@ func TestFromJSONArraySpace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetStringValue(t *testing.T) {
|
||||
dflt := map[string]struct{}{}
|
||||
dflt := utils.StringSet{}
|
||||
expected := "10"
|
||||
if rply := getStringValue(int64(10), dflt); rply != expected {
|
||||
t.Errorf("Expecting: %s , received: %s", expected, rply)
|
||||
@@ -153,7 +153,7 @@ func TestGetStringValue(t *testing.T) {
|
||||
expected = `{"ID":"id1","TimeValue":"1s"}`
|
||||
if rply := getStringValue(map[string]interface{}{
|
||||
"ID": "id1",
|
||||
"TimeValue": int64(time.Second)}, map[string]struct{}{"TimeValue": {}}); rply != expected {
|
||||
"TimeValue": int64(time.Second)}, utils.StringSet{"TimeValue": {}}); rply != expected {
|
||||
t.Errorf("Expecting: %s , received: %s", expected, rply)
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ func TestGetStringValue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetSliceAsString(t *testing.T) {
|
||||
dflt := map[string]struct{}{}
|
||||
dflt := utils.StringSet{}
|
||||
expected := "[10,20,30]"
|
||||
if rply := getSliceAsString([]interface{}{10, 20, 30}, dflt); rply != expected {
|
||||
t.Errorf("Expecting: %s , received: %s", expected, rply)
|
||||
@@ -177,7 +177,7 @@ func TestGetSliceAsString(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMapAsString(t *testing.T) {
|
||||
dflt := map[string]struct{}{}
|
||||
dflt := utils.StringSet{}
|
||||
expected := `{"ID":"id1","TimeValue":10000}`
|
||||
if rply := getStringValue(map[string]interface{}{
|
||||
"ID": "id1",
|
||||
@@ -188,13 +188,13 @@ func TestGetMapAsString(t *testing.T) {
|
||||
expected = `{"ID":"id1","TimeValue":"1s"}`
|
||||
if rply := getStringValue(map[string]interface{}{
|
||||
"ID": "id1",
|
||||
"TimeValue": int64(time.Second)}, map[string]struct{}{"TimeValue": {}}); rply != expected {
|
||||
"TimeValue": int64(time.Second)}, utils.StringSet{"TimeValue": {}}); rply != expected {
|
||||
t.Errorf("Expecting: %s , received: %s", expected, rply)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFormatedResult(t *testing.T) {
|
||||
dflt := map[string]struct{}{}
|
||||
dflt := utils.StringSet{}
|
||||
expected := `{
|
||||
"ID": "id1",
|
||||
"TimeValue": 10000
|
||||
@@ -211,7 +211,7 @@ func TestGetFormatedResult(t *testing.T) {
|
||||
}`
|
||||
if rply := GetFormatedResult(map[string]interface{}{
|
||||
"ID": "id1",
|
||||
"TimeValue": int64(time.Second)}, map[string]struct{}{"TimeValue": {}}); rply != expected {
|
||||
"TimeValue": int64(time.Second)}, utils.StringSet{"TimeValue": {}}); rply != expected {
|
||||
t.Errorf("Expecting: %s , received: %s", expected, rply)
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ func TestGetFormatedResult(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetFormatedSliceResult(t *testing.T) {
|
||||
dflt := map[string]struct{}{}
|
||||
dflt := utils.StringSet{}
|
||||
expected := "[10,20,30]"
|
||||
if rply := getSliceAsString([]interface{}{10, 20, 30}, dflt); rply != expected {
|
||||
t.Errorf("Expecting: %s , received: %s", expected, rply)
|
||||
|
||||
@@ -72,7 +72,7 @@ func (self *CmdGetCost) ClientArgs() []string {
|
||||
}
|
||||
|
||||
func (self *CmdGetCost) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"Usage": {},
|
||||
"GroupIntervalStart": {},
|
||||
"RateIncrement": {},
|
||||
|
||||
@@ -65,7 +65,7 @@ func (self *CmdGetCostDetails) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdGetCostDetails) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"Usage": {},
|
||||
"GroupIntervalStart": {},
|
||||
"RateIncrement": {},
|
||||
|
||||
@@ -71,7 +71,7 @@ func (self *CmdGetDataCost) ClientArgs() []string {
|
||||
}
|
||||
|
||||
func (self *CmdGetDataCost) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"Usage": {},
|
||||
"GroupIntervalStart": {},
|
||||
"RateIncrement": {},
|
||||
|
||||
@@ -67,7 +67,7 @@ func (self *CmdPassiveSessions) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdPassiveSessions) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedSliceResult(result, map[string]struct{}{
|
||||
return GetFormatedSliceResult(result, utils.StringSet{
|
||||
"Usage": {},
|
||||
"DurationIndex": {},
|
||||
"MaxRateUnit": {},
|
||||
|
||||
@@ -66,7 +66,7 @@ func (self *CmdGetResourceProfile) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdGetResourceProfile) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"UsageTTL": {},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (self *CmdSessionsInitiate) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdSessionsInitiate) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"Usage": {},
|
||||
"MaxUsage": {},
|
||||
})
|
||||
|
||||
@@ -76,7 +76,7 @@ func (self *CmdSessionsProcessEvent) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdSessionsProcessEvent) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"Usage": {},
|
||||
"MaxUsage": {},
|
||||
})
|
||||
|
||||
@@ -76,7 +76,7 @@ func (self *CmdSessionsUpdate) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdSessionsUpdate) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"Usage": {},
|
||||
"MaxUsage": {},
|
||||
})
|
||||
|
||||
@@ -66,7 +66,7 @@ func (self *CmdGetStatQueueProfile) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdGetStatQueueProfile) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"TTL": {},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (self *CmdGetThreshold) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdGetThreshold) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"MinSleep": {},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (self *CmdGetThresholdProfile) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdGetThresholdProfile) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedResult(result, map[string]struct{}{
|
||||
return GetFormatedResult(result, utils.StringSet{
|
||||
"MinSleep": {},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func (self *CmdGetTriggers) RpcResult() interface{} {
|
||||
}
|
||||
|
||||
func (self *CmdGetTriggers) GetFormatedResult(result interface{}) string {
|
||||
return GetFormatedSliceResult(result, map[string]struct{}{
|
||||
return GetFormatedSliceResult(result, utils.StringSet{
|
||||
"MinSleep": {},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -76,28 +76,3 @@ func CachedDestHasPrefix(destId, prefix string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/*func CleanStalePrefixes(destIds []string) {
|
||||
utils.Logger.Info("Cleaning stale dest prefixes: " + utils.ToJSON(destIds))
|
||||
prefixMap := cache.GetAllEntries(utils.REVERSE_DESTINATION_PREFIX)
|
||||
for prefix, idIDs := range prefixMap {
|
||||
dIDs := idIDs.(map[string]struct{})
|
||||
changed := false
|
||||
for _, searchedDID := range destIds {
|
||||
if _, found := dIDs[searchedDID]; found {
|
||||
if len(dIDs) == 1 {
|
||||
// remove de prefix from cache
|
||||
cache.RemKey(utils.REVERSE_DESTINATION_PREFIX + prefix)
|
||||
} else {
|
||||
// delete the destination from list and put the new list in chache
|
||||
delete(dIDs, searchedDID)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
cache.Set(utils.REVERSE_DESTINATION_PREFIX+prefix, dIDs)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -123,24 +123,6 @@ func TestDestinationNonCachedDestWrongPrefix(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestCleanStalePrefixes(t *testing.T) {
|
||||
x := struct{}{}
|
||||
cache.Set(utils.DESTINATION_PREFIX+"1", map[string]struct{}{"D1": x, "D2": x})
|
||||
cache.Set(utils.DESTINATION_PREFIX+"2", map[string]struct{}{"D1": x})
|
||||
cache.Set(utils.DESTINATION_PREFIX+"3", map[string]struct{}{"D2": x})
|
||||
CleanStalePrefixes([]string{"D1"})
|
||||
if r, ok := cache.Get(utils.DESTINATION_PREFIX + "1"); !ok || len(r.(map[string]struct{})) != 1 {
|
||||
t.Error("Error cleaning stale destination ids", r)
|
||||
}
|
||||
if r, ok := cache.Get(utils.DESTINATION_PREFIX + "2"); ok {
|
||||
t.Error("Error removing stale prefix: ", r)
|
||||
}
|
||||
if r, ok := cache.Get(utils.DESTINATION_PREFIX + "3"); !ok || len(r.(map[string]struct{})) != 1 {
|
||||
t.Error("Error performing stale cleaning: ", r)
|
||||
}
|
||||
}*/
|
||||
|
||||
/********************************* Benchmarks **********************************/
|
||||
|
||||
func BenchmarkDestinationStorageStoreRestore(b *testing.B) {
|
||||
|
||||
@@ -267,7 +267,7 @@ func (sq *StatQueue) Compress(maxQL int64, roundDec int) bool {
|
||||
}
|
||||
var newSQItems []SQItem
|
||||
sqMap := make(map[string]*time.Time)
|
||||
idMap := make(map[string]struct{})
|
||||
idMap := make(utils.StringSet)
|
||||
defaultCompressID := sq.SQItems[len(sq.SQItems)-1].EventID
|
||||
defaultTTL := sq.SQItems[len(sq.SQItems)-1].ExpiryTime
|
||||
|
||||
@@ -277,7 +277,7 @@ func (sq *StatQueue) Compress(maxQL int64, roundDec int) bool {
|
||||
|
||||
for _, m := range sq.SQMetrics {
|
||||
for _, id := range m.Compress(maxQL, defaultCompressID, roundDec) {
|
||||
idMap[id] = struct{}{}
|
||||
idMap.Add(id)
|
||||
}
|
||||
}
|
||||
for k := range idMap {
|
||||
|
||||
@@ -900,14 +900,14 @@ func (pdd *StatPDD) GetCompressFactor(events map[string]int) map[string]int {
|
||||
}
|
||||
|
||||
func NewDDC(minItems int, extraParams string, filterIDs []string) (StatMetric, error) {
|
||||
return &StatDDC{Events: make(map[string]map[string]int64), FieldValues: make(map[string]map[string]struct{}),
|
||||
return &StatDDC{Events: make(map[string]map[string]int64), FieldValues: make(map[string]utils.StringSet),
|
||||
MinItems: minItems, FilterIDs: filterIDs}, nil
|
||||
}
|
||||
|
||||
type StatDDC struct {
|
||||
FilterIDs []string
|
||||
FieldValues map[string]map[string]struct{} // map[fieldValue]map[eventID]
|
||||
Events map[string]map[string]int64 // map[EventTenantID]map[fieldValue]compressfactor
|
||||
FieldValues map[string]utils.StringSet // map[fieldValue]map[eventID]
|
||||
Events map[string]map[string]int64 // map[EventTenantID]map[fieldValue]compressfactor
|
||||
MinItems int
|
||||
Count int64
|
||||
}
|
||||
@@ -948,9 +948,9 @@ func (ddc *StatDDC) AddEvent(evID string, ev utils.DataProvider) (err error) {
|
||||
|
||||
// add to fieldValues
|
||||
if _, has := ddc.FieldValues[fieldValue]; !has {
|
||||
ddc.FieldValues[fieldValue] = make(map[string]struct{})
|
||||
ddc.FieldValues[fieldValue] = make(utils.StringSet)
|
||||
}
|
||||
ddc.FieldValues[fieldValue][evID] = struct{}{}
|
||||
ddc.FieldValues[fieldValue].Add(evID)
|
||||
|
||||
// add to events
|
||||
if _, has := ddc.Events[evID]; !has {
|
||||
@@ -992,8 +992,8 @@ func (ddc *StatDDC) RemEvent(evID string) (err error) {
|
||||
if _, has := ddc.FieldValues[fieldValue]; !has {
|
||||
return
|
||||
}
|
||||
delete(ddc.FieldValues[fieldValue], evID)
|
||||
if len(ddc.FieldValues[fieldValue]) <= 0 {
|
||||
ddc.FieldValues[fieldValue].Remove(evID)
|
||||
if ddc.FieldValues[fieldValue].Size() <= 0 {
|
||||
delete(ddc.FieldValues, fieldValue)
|
||||
}
|
||||
return
|
||||
@@ -1309,14 +1309,14 @@ func (avg *StatAverage) GetCompressFactor(events map[string]int) map[string]int
|
||||
}
|
||||
|
||||
func NewStatDistinct(minItems int, extraParams string, filterIDs []string) (StatMetric, error) {
|
||||
return &StatDistinct{Events: make(map[string]map[string]int64), FieldValues: make(map[string]map[string]struct{}),
|
||||
return &StatDistinct{Events: make(map[string]map[string]int64), FieldValues: make(map[string]utils.StringSet),
|
||||
MinItems: minItems, FieldName: extraParams, FilterIDs: filterIDs}, nil
|
||||
}
|
||||
|
||||
type StatDistinct struct {
|
||||
FilterIDs []string
|
||||
FieldValues map[string]map[string]struct{} // map[fieldValue]map[eventID]
|
||||
Events map[string]map[string]int64 // map[EventTenantID]map[fieldValue]compressfactor
|
||||
FieldValues map[string]utils.StringSet // map[fieldValue]map[eventID]
|
||||
Events map[string]map[string]int64 // map[EventTenantID]map[fieldValue]compressfactor
|
||||
MinItems int
|
||||
FieldName string
|
||||
Count int64
|
||||
@@ -1363,9 +1363,9 @@ func (dst *StatDistinct) AddEvent(evID string, ev utils.DataProvider) (err error
|
||||
|
||||
// add to fieldValues
|
||||
if _, has := dst.FieldValues[fieldValue]; !has {
|
||||
dst.FieldValues[fieldValue] = make(map[string]struct{})
|
||||
dst.FieldValues[fieldValue] = make(utils.StringSet)
|
||||
}
|
||||
dst.FieldValues[fieldValue][evID] = struct{}{}
|
||||
dst.FieldValues[fieldValue].Add(evID)
|
||||
|
||||
// add to events
|
||||
if _, has := dst.Events[evID]; !has {
|
||||
@@ -1407,8 +1407,8 @@ func (dst *StatDistinct) RemEvent(evID string) (err error) {
|
||||
if _, has := dst.FieldValues[fieldValue]; !has {
|
||||
return
|
||||
}
|
||||
delete(dst.FieldValues[fieldValue], evID)
|
||||
if len(dst.FieldValues[fieldValue]) <= 0 {
|
||||
dst.FieldValues[fieldValue].Remove(evID)
|
||||
if dst.FieldValues[fieldValue].Size() <= 0 {
|
||||
delete(dst.FieldValues, fieldValue)
|
||||
}
|
||||
return
|
||||
|
||||
@@ -2014,7 +2014,7 @@ func TestDDCGetStringValue2(t *testing.T) {
|
||||
func TestDDCCompress(t *testing.T) {
|
||||
ddc := &StatDDC{
|
||||
Events: make(map[string]map[string]int64),
|
||||
FieldValues: make(map[string]map[string]struct{}),
|
||||
FieldValues: make(map[string]utils.StringSet),
|
||||
MinItems: 2,
|
||||
FilterIDs: []string{},
|
||||
}
|
||||
@@ -2027,7 +2027,7 @@ func TestDDCCompress(t *testing.T) {
|
||||
"1002": 1,
|
||||
},
|
||||
},
|
||||
FieldValues: map[string]map[string]struct{}{
|
||||
FieldValues: map[string]utils.StringSet{
|
||||
"1001": {
|
||||
"EVENT_1": {},
|
||||
},
|
||||
@@ -2775,7 +2775,7 @@ func TestStatDistinctGetStringValue2(t *testing.T) {
|
||||
func TestStatDistinctCompress(t *testing.T) {
|
||||
ddc := &StatDistinct{
|
||||
Events: make(map[string]map[string]int64),
|
||||
FieldValues: make(map[string]map[string]struct{}),
|
||||
FieldValues: make(map[string]utils.StringSet),
|
||||
MinItems: 2,
|
||||
FilterIDs: []string{},
|
||||
FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination,
|
||||
@@ -2789,7 +2789,7 @@ func TestStatDistinctCompress(t *testing.T) {
|
||||
"1002": 1,
|
||||
},
|
||||
},
|
||||
FieldValues: map[string]map[string]struct{}{
|
||||
FieldValues: map[string]utils.StringSet{
|
||||
"1001": {
|
||||
"EVENT_1": {},
|
||||
},
|
||||
|
||||
@@ -190,7 +190,7 @@ func NewGoogleCSVStorage(sep rune, spreadsheetID string) (*CSVStorage, error) {
|
||||
return nil, err
|
||||
}
|
||||
getIfExist := func(name string) []string {
|
||||
if _, has := sheetNames[name]; has {
|
||||
if sheetNames.Has(name) {
|
||||
return []string{name}
|
||||
}
|
||||
return []string{}
|
||||
@@ -854,15 +854,15 @@ func newSheet() (sht *sheets.Service, err error) { //*google_api
|
||||
return
|
||||
}
|
||||
|
||||
func getSpreatsheetTabs(spreadsheetID string, srv *sheets.Service) (sheetsName map[string]struct{}, err error) {
|
||||
sheetsName = make(map[string]struct{})
|
||||
func getSpreatsheetTabs(spreadsheetID string, srv *sheets.Service) (sheetsName utils.StringSet, err error) {
|
||||
sheetsName = make(utils.StringSet)
|
||||
sht, err := srv.Spreadsheets.Get(spreadsheetID).Do()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Unable get the information about spreadsheet because: %v", err)
|
||||
return
|
||||
}
|
||||
for _, sheet := range sht.Sheets {
|
||||
sheetsName[sheet.Properties.Title] = struct{}{}
|
||||
sheetsName.Add(sheet.Properties.Title)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -34,19 +34,19 @@ import (
|
||||
)
|
||||
|
||||
func (ms *MongoStorage) GetTpIds(colName string) (tpids []string, err error) {
|
||||
getTpIDs := func(ctx context.Context, col string, tpMap map[string]struct{}) (map[string]struct{}, error) {
|
||||
getTpIDs := func(ctx context.Context, col string, tpMap utils.StringSet) (utils.StringSet, error) {
|
||||
if strings.HasPrefix(col, "tp_") {
|
||||
result, err := ms.getCol(col).Distinct(ctx, "tpid", bson.D{})
|
||||
if err != nil {
|
||||
return tpMap, err
|
||||
}
|
||||
for _, tpid := range result {
|
||||
tpMap[tpid.(string)] = struct{}{}
|
||||
tpMap.Add(tpid.(string))
|
||||
}
|
||||
}
|
||||
return tpMap, nil
|
||||
}
|
||||
tpidMap := make(map[string]struct{})
|
||||
tpidMap := make(utils.StringSet)
|
||||
|
||||
if colName == "" {
|
||||
if err := ms.query(func(sctx mongo.SessionContext) error {
|
||||
@@ -75,9 +75,7 @@ func (ms *MongoStorage) GetTpIds(colName string) (tpids []string, err error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for tpid := range tpidMap {
|
||||
tpids = append(tpids, tpid)
|
||||
}
|
||||
tpids = tpidMap.AsSlice()
|
||||
return tpids, nil
|
||||
}
|
||||
|
||||
|
||||
11
ers/ers.go
11
ers/ers.go
@@ -95,7 +95,7 @@ func (erS *ERService) ListenAndServe(stopChan, cfgRldChan chan struct{}) (err er
|
||||
}
|
||||
case <-cfgRldChan: // handle reload
|
||||
cfgIDs := make(map[string]int)
|
||||
pathReloaded := make(map[string]struct{})
|
||||
pathReloaded := make(utils.StringSet)
|
||||
// index config IDs
|
||||
for i, rdrCfg := range erS.cfg.ERsCfg().Readers {
|
||||
cfgIDs[rdrCfg.ID] = i
|
||||
@@ -109,7 +109,7 @@ func (erS *ERService) ListenAndServe(stopChan, cfgRldChan chan struct{}) (err er
|
||||
newCfg.ID == rdr.Config().ID { // make sure the index did not change
|
||||
continue
|
||||
}
|
||||
pathReloaded[id] = struct{}{}
|
||||
pathReloaded.Add(id)
|
||||
}
|
||||
delete(erS.rdrs, id)
|
||||
close(erS.stopLsn[id])
|
||||
@@ -117,10 +117,9 @@ func (erS *ERService) ListenAndServe(stopChan, cfgRldChan chan struct{}) (err er
|
||||
}
|
||||
// add new ids
|
||||
for id, rdrIdx := range cfgIDs {
|
||||
if _, has := erS.rdrs[id]; has {
|
||||
if _, has := pathReloaded[id]; !has {
|
||||
continue
|
||||
}
|
||||
if _, has := erS.rdrs[id]; has &&
|
||||
!pathReloaded.Has(id) {
|
||||
continue
|
||||
}
|
||||
if erS.cfg.ERsCfg().Readers[rdrIdx].Type == utils.META_NONE { // ignore *default reader
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user