MemoryManager.GetAll() return random policies
datastream opened this issue · 1 comments
datastream commented
If I call memory.GetAll(10,0), every time it return different data.
ladon/manager/memory/manager_memory.go
Line 54 in d66f876
so I think this function should be sort first.
var keys []string
m. RLock()
start, end := pagination.Index(int(limit), int(offset), len(m.Policies))
for key, p := range m.Policies {
keys = append(keys, key)
}
sort.Ints(keys)
var rst []Policies
for _, key := range keys[start:end] {
rst = append(rst, m.Policies[key])
}
m. RUnlock()
return rst, nil
aeneasr commented
It would probably be better to change the internal storage of the policies from a map to a slice, which would save us some time sorting and appending here. As a side note, var keys []string
is not initialized so append
will allocate by power of 2 which takes a lot of time in pressure environments. You can save a lot of unnecessary allocation with keys := make([]string, len(m.Policies))
Feel free to PR according to my feedback!