@@ -691,16 +691,17 @@ func (r *MongoRepository) GetNextExecutionNumber(ctx context.Context, name strin
691
691
}
692
692
693
693
func (r * MongoRepository ) GetExecutionTags (ctx context.Context , testWorkflowName string ) (tags map [string ][]string , err error ) {
694
- query := bson.M {"tags" : bson.M {"$exists " : true }}
694
+ query := bson.M {"tags" : bson.M {"$nin " : bson. A { nil , bson. M {}} }}
695
695
if testWorkflowName != "" {
696
696
query ["workflow.name" ] = testWorkflowName
697
697
}
698
698
699
699
pipeline := []bson.M {
700
700
{"$match" : query },
701
- {"$project" : bson.M {
702
- "tags" : 1 ,
703
- }},
701
+ {"$project" : bson.M {"_id" : 0 , "tags" : bson.M {"$objectToArray" : "$tags" }}},
702
+ {"$unwind" : "$tags" },
703
+ {"$group" : bson.M {"_id" : "$tags.k" , "values" : bson.M {"$addToSet" : "$tags.v" }}},
704
+ {"$project" : bson.M {"_id" : 0 , "name" : "$_id" , "values" : 1 }},
704
705
}
705
706
706
707
opts := options .Aggregate ()
@@ -713,21 +714,18 @@ func (r *MongoRepository) GetExecutionTags(ctx context.Context, testWorkflowName
713
714
return nil , err
714
715
}
715
716
716
- var executions []testkube.TestWorkflowExecutionTags
717
- err = cursor .All (ctx , & executions )
717
+ var res []struct {
718
+ Name string `bson:"name"`
719
+ Values []string `bson:"values"`
720
+ }
721
+ err = cursor .All (ctx , & res )
718
722
if err != nil {
719
723
return nil , err
720
724
}
721
725
722
- for i := range executions {
723
- executions [i ].UnscapeDots ()
724
- }
725
-
726
726
tags = make (map [string ][]string )
727
- for _ , execution := range executions {
728
- for key , value := range execution .Tags {
729
- tags [key ] = append (tags [key ], value )
730
- }
727
+ for _ , tag := range res {
728
+ tags [tag .Name ] = tag .Values
731
729
}
732
730
733
731
return tags , nil
0 commit comments