@@ -551,19 +551,31 @@ func (s *service) ExpandViews(ctx context.Context, subs []subscription.Subscript
551551 var featsOfItems pagination.Result [feature.Feature ]
552552
553553 {
554- itemsWithFeatures := lo .Filter (items , func (i subscription.SubscriptionItem , _ int ) bool {
555- return i .RateCard .AsMeta ().FeatureKey != nil
556- })
554+ uniqFeatureKeyOrIDs := func () []string {
555+ keyOrIDS := make (map [string ]struct {}, len (items ))
557556
558- uniqFeatureKeys := lo .Uniq (slicesx .Map (itemsWithFeatures , func (i subscription.SubscriptionItem ) string {
559- return lo .FromPtr (i .RateCard .AsMeta ().FeatureKey )
560- }))
557+ for _ , item := range items {
558+ fKey , fID := lo .FromPtr (item .RateCard .AsMeta ().FeatureKey ), lo .FromPtr (item .RateCard .AsMeta ().FeatureID )
559+
560+ if fKey != "" {
561+ keyOrIDS [fKey ] = struct {}{}
562+ }
561563
562- if len (uniqFeatureKeys ) > 0 {
564+ if fID != "" {
565+ keyOrIDS [fID ] = struct {}{}
566+ }
567+ }
568+
569+ return lo .MapToSlice (keyOrIDS , func (key string , _ struct {}) string {
570+ return key
571+ })
572+ }()
573+
574+ if len (uniqFeatureKeyOrIDs ) > 0 {
563575 featsOfItems , err = s .FeatureService .ListFeatures (ctx , feature.ListFeaturesParams {
564576 Namespace : cus .Namespace ,
565577 IncludeArchived : true ,
566- IDsOrKeys : uniqFeatureKeys ,
578+ IDsOrKeys : uniqFeatureKeyOrIDs ,
567579 })
568580 if err != nil {
569581 return nil , fmt .Errorf ("failed to get features of items: %w" , err )
@@ -637,12 +649,24 @@ func (s *service) ExpandViews(ctx context.Context, subs []subscription.Subscript
637649 featsOfItemsBySub := lo .MapEntries (itemsBySub , func (key string , items []subscription.SubscriptionItem ) (string , []feature.Feature ) {
638650 found := make ([]feature.Feature , 0 )
639651 for _ , item := range items {
640- if item .RateCard .AsMeta ().FeatureKey == nil {
652+ fKey , fID := lo .FromPtr (item .RateCard .AsMeta ().FeatureKey ), lo .FromPtr (item .RateCard .AsMeta ().FeatureID )
653+
654+ if fKey == "" && fID == "" {
641655 continue
642656 }
643657
644658 feat , ok := lo .Find (featsOfItems .Items , func (f feature.Feature ) bool {
645- return f .Key == lo .FromPtr (item .RateCard .AsMeta ().FeatureKey )
659+ var featFound bool
660+
661+ if fKey != "" {
662+ featFound = f .Key == fKey
663+ }
664+
665+ if fID != "" {
666+ featFound = f .ID == fID
667+ }
668+
669+ return featFound
646670 })
647671 if ok {
648672 found = append (found , feat )
0 commit comments