From 1c9bd9d4f23683c34a80d7d205c8be389c6b595a Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 4 Dec 2020 16:04:01 +0200 Subject: [PATCH] Replaced map[string]struct{} with utils.StringSet --- agents/libdns.go | 8 ++++---- console/accounts.go | 2 +- console/active_sessions.go | 2 +- console/attributes_process_event.go | 2 +- console/chargers_process_event.go | 2 +- console/command_executer.go | 12 ++++++------ console/command_executer_test.go | 16 ++++++++-------- console/cost.go | 2 +- console/cost_details.go | 2 +- console/datacost.go | 2 +- console/passive_sessions.go | 2 +- console/resources_profile.go | 2 +- console/session_initiate.go | 2 +- console/session_process_message.go | 2 +- console/session_update.go | 2 +- console/stats_profile.go | 2 +- console/threshold.go | 2 +- console/thresholds_profile.go | 2 +- console/triggers.go | 2 +- engine/destinations.go | 25 ------------------------- engine/destinations_test.go | 18 ------------------ engine/libstats.go | 4 ++-- engine/statmetrics.go | 28 ++++++++++++++-------------- engine/statmetrics_test.go | 8 ++++---- engine/storage_csv.go | 8 ++++---- engine/storage_mongo_stordb.go | 10 ++++------ ers/ers.go | 11 +++++------ 27 files changed, 67 insertions(+), 113 deletions(-) diff --git a/agents/libdns.go b/agents/libdns.go index 629b05a0d..4578fec5b 100644 --- a/agents/libdns.go +++ b/agents/libdns.go @@ -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 diff --git a/console/accounts.go b/console/accounts.go index a077adb80..2844c96ed 100644 --- a/console/accounts.go +++ b/console/accounts.go @@ -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": {}, }) } diff --git a/console/active_sessions.go b/console/active_sessions.go index 5799ba555..2657cf607 100644 --- a/console/active_sessions.go +++ b/console/active_sessions.go @@ -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": {}, diff --git a/console/attributes_process_event.go b/console/attributes_process_event.go index 2623f6d40..c0a520e37 100644 --- a/console/attributes_process_event.go +++ b/console/attributes_process_event.go @@ -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": {}, }) } diff --git a/console/chargers_process_event.go b/console/chargers_process_event.go index e42a4023f..2f704cc2d 100644 --- a/console/chargers_process_event.go +++ b/console/chargers_process_event.go @@ -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": {}, }) } diff --git a/console/command_executer.go b/console/command_executer.go index 3612fcdf9..53be29c4b 100644 --- a/console/command_executer.go +++ b/console/command_executer.go @@ -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 { diff --git a/console/command_executer_test.go b/console/command_executer_test.go index df8faae05..317e7b4fb 100644 --- a/console/command_executer_test.go +++ b/console/command_executer_test.go @@ -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) diff --git a/console/cost.go b/console/cost.go index eeb9b4057..08e35b57f 100644 --- a/console/cost.go +++ b/console/cost.go @@ -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": {}, diff --git a/console/cost_details.go b/console/cost_details.go index a1f163058..af38265ad 100644 --- a/console/cost_details.go +++ b/console/cost_details.go @@ -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": {}, diff --git a/console/datacost.go b/console/datacost.go index 2728ce29d..8b986ef3f 100644 --- a/console/datacost.go +++ b/console/datacost.go @@ -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": {}, diff --git a/console/passive_sessions.go b/console/passive_sessions.go index 136d9fe15..05286ec75 100644 --- a/console/passive_sessions.go +++ b/console/passive_sessions.go @@ -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": {}, diff --git a/console/resources_profile.go b/console/resources_profile.go index 1e737d35d..1afd5e297 100644 --- a/console/resources_profile.go +++ b/console/resources_profile.go @@ -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": {}, }) } diff --git a/console/session_initiate.go b/console/session_initiate.go index a80a6b8c3..2d16eb7ab 100644 --- a/console/session_initiate.go +++ b/console/session_initiate.go @@ -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": {}, }) diff --git a/console/session_process_message.go b/console/session_process_message.go index f290e4c6c..59d3f5fb6 100644 --- a/console/session_process_message.go +++ b/console/session_process_message.go @@ -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": {}, }) diff --git a/console/session_update.go b/console/session_update.go index 8f3985565..a8af6c98e 100644 --- a/console/session_update.go +++ b/console/session_update.go @@ -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": {}, }) diff --git a/console/stats_profile.go b/console/stats_profile.go index d33973667..b33532c27 100644 --- a/console/stats_profile.go +++ b/console/stats_profile.go @@ -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": {}, }) } diff --git a/console/threshold.go b/console/threshold.go index 1dbc963f7..732a6b8d1 100644 --- a/console/threshold.go +++ b/console/threshold.go @@ -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": {}, }) } diff --git a/console/thresholds_profile.go b/console/thresholds_profile.go index b023707fa..53d67097b 100644 --- a/console/thresholds_profile.go +++ b/console/thresholds_profile.go @@ -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": {}, }) } diff --git a/console/triggers.go b/console/triggers.go index dc76fd4b9..c6587cfc6 100644 --- a/console/triggers.go +++ b/console/triggers.go @@ -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": {}, }) } diff --git a/engine/destinations.go b/engine/destinations.go index 4b881a692..2be937a54 100644 --- a/engine/destinations.go +++ b/engine/destinations.go @@ -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) - } - } -} -*/ diff --git a/engine/destinations_test.go b/engine/destinations_test.go index 63d2bf259..1f2650410 100644 --- a/engine/destinations_test.go +++ b/engine/destinations_test.go @@ -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) { diff --git a/engine/libstats.go b/engine/libstats.go index d16b78f92..453bfe23d 100644 --- a/engine/libstats.go +++ b/engine/libstats.go @@ -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 { diff --git a/engine/statmetrics.go b/engine/statmetrics.go index ff7cc2b06..6bb7bb4c6 100644 --- a/engine/statmetrics.go +++ b/engine/statmetrics.go @@ -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 diff --git a/engine/statmetrics_test.go b/engine/statmetrics_test.go index 0b3778281..b5e486b45 100644 --- a/engine/statmetrics_test.go +++ b/engine/statmetrics_test.go @@ -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": {}, }, diff --git a/engine/storage_csv.go b/engine/storage_csv.go index 836fe0a3c..856cbb761 100644 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -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 } diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index 9baa722f5..1a4b7cbab 100644 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -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 } diff --git a/ers/ers.go b/ers/ers.go index 43b4c0c4c..958c0e2e3 100644 --- a/ers/ers.go +++ b/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