item.get cache won't be hit if tags order are different (#1745)

* cache won't be hit if tags order are not the same

* unit test for get items with tags
This commit is contained in:
Muhammad Iqbal Alaydrus
2023-12-04 19:46:11 +07:00
committed by GitHub
parent 0f144f64d9
commit dfe360bf1d
2 changed files with 61 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package zabbix
import (
"context"
"sort"
"strconv"
"strings"
@@ -402,6 +403,13 @@ func (ds *Zabbix) GetAllItems(ctx context.Context, hostids []string, appids []st
}
tagsParams = append(tagsParams, tagParam)
}
// tags order should be handled for higher cache hit ratio
sort.Slice(tagsParams, func(i, j int) bool {
if tagsParams[i]["tag"] != tagsParams[j]["tag"] {
return tagsParams[i]["tag"] < tagsParams[j]["tag"]
}
return tagsParams[i]["value"] < tagsParams[j]["value"]
})
params["tags"] = tagsParams
params["evaltype"] = 2
}