Compare commits

..

1 Commits

Author SHA1 Message Date
Airat Arifullin 465d0b10f1 [#XX] policy: Fix IteratorChainsByPrefix method
DCO action / DCO (pull_request) Successful in 1m9s Details
Tests / Tests (1.19) (pull_request) Successful in 1m31s Details
Tests / Tests (1.20) (pull_request) Successful in 1m32s Details
* If numeric mapping does not exists, then assign id to 0.
* Add check to unit-test.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-04-03 17:44:55 +03:00
1 changed files with 6 additions and 4 deletions

View File

@ -112,9 +112,6 @@ func mapKey(kind Kind, name []byte) []byte {
// a storage key shortening long names. Short entity
// names are also mapped to prevent collisions in the map.
func mapToNumeric(ctx storage.Context, kind Kind, name []byte) (mapped int, mappingExists bool) {
mapped = 0
mappingExists = false
mKey := mapKey(kind, name)
numericID := storage.Get(ctx, mKey)
if numericID == nil {
@ -246,7 +243,12 @@ func ListChainsByPrefix(entity Kind, entityName string, prefix []byte) [][]byte
func IteratorChainsByPrefix(entity Kind, entityName string, prefix []byte) iterator.Iterator {
ctx := storage.GetReadOnlyContext()
id, _ := mapToNumeric(ctx, entity, []byte(entityName))
id, mappingExists := mapToNumeric(ctx, entity, []byte(entityName))
if !mappingExists {
// All exising numeric mappings starts with 1. So, if id is set to 0, then
// iterator will iterate over empty list of chains.
id = 0
}
keyPrefix := storageKey(entity, id, prefix)
return storage.Find(ctx, keyPrefix, storage.ValuesOnly)
}