From 58789fbf6248c6e4e86d74ff5dcf92a475c6537b Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Mon, 18 Dec 2023 16:15:10 -0600 Subject: [PATCH] Index multivalued attributes. --- x/registry/keeper/keeper.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/x/registry/keeper/keeper.go b/x/registry/keeper/keeper.go index e252e0ec..dfc3fa7f 100644 --- a/x/registry/keeper/keeper.go +++ b/x/registry/keeper/keeper.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "reflect" "sort" "time" @@ -349,9 +350,24 @@ func (k Keeper) ProcessAttributes(ctx sdk.Context, record types.RecordType) erro { // #nosec G705 for key := range record.Attributes { - indexKey := GetAttributesIndexKey(key, record.Attributes[key]) - if err := k.SetAttributeMapping(ctx, indexKey, record.ID); err != nil { - return err + attr := record.Attributes[key] + rt := reflect.TypeOf(attr) + 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 + } } } }