129: Index multivalued attributes. #128

Merged
telackey merged 4 commits from telackey/tags into main 2023-12-19 06:55:12 +00:00
Showing only changes of commit 58789fbf62 - Show all commits

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"reflect"
"sort" "sort"
"time" "time"
@ -349,9 +350,24 @@ func (k Keeper) ProcessAttributes(ctx sdk.Context, record types.RecordType) erro
{ {
// #nosec G705 // #nosec G705
for key := range record.Attributes { for key := range record.Attributes {
indexKey := GetAttributesIndexKey(key, record.Attributes[key]) attr := record.Attributes[key]
if err := k.SetAttributeMapping(ctx, indexKey, record.ID); err != nil { rt := reflect.TypeOf(attr)
return err switch rt.Kind() {
case reflect.Slice:
av := attr.([]interface{})
for i := range av {
indexKey := GetAttributesIndexKey(key, av[i])
k.Logger(ctx).Error(fmt.Sprintf("attr indexKey: %s", indexKey))
if err := k.SetAttributeMapping(ctx, indexKey, record.ID); err != nil {
return err
}
}
default:
indexKey := GetAttributesIndexKey(key, attr)
k.Logger(ctx).Error(fmt.Sprintf("attr indexKey: %s", indexKey))
if err := k.SetAttributeMapping(ctx, indexKey, record.ID); err != nil {
return err
}
} }
} }
} }