@@ -3058,7 +3058,7 @@ func (q *FakeQuerier) GetTemplateAppInsights(ctx context.Context, arg database.G
3058
3058
// FROM
3059
3059
for _ , stat := range q .templateUsageStats {
3060
3060
// WHERE
3061
- if stat .StartTime .Before (arg .StartTime ) || stat .StartTime .After (arg .EndTime ) {
3061
+ if stat .StartTime .Before (arg .StartTime ) || stat .EndTime .After (arg .EndTime ) {
3062
3062
continue
3063
3063
}
3064
3064
if len (arg .TemplateIDs ) > 0 && ! slices .Contains (arg .TemplateIDs , stat .TemplateID ) {
@@ -3118,20 +3118,20 @@ func (q *FakeQuerier) GetTemplateAppInsights(ctx context.Context, arg database.G
3118
3118
}
3119
3119
3120
3120
templateRows := make (map [appGroupBy ]templateRow )
3121
- for _ , row := range appInsightRows {
3121
+ for _ , aiRow := range appInsightRows {
3122
3122
key := appGroupBy {
3123
- AppName : row .AppName ,
3124
- DisplayName : row .DisplayName ,
3125
- Icon : row .Icon ,
3126
- IsApp : row .IsApp ,
3123
+ AppName : aiRow .AppName ,
3124
+ DisplayName : aiRow .DisplayName ,
3125
+ Icon : aiRow .Icon ,
3126
+ IsApp : aiRow .IsApp ,
3127
3127
}
3128
3128
row , ok := templateRows [key ]
3129
3129
if ! ok {
3130
3130
row = templateRow {
3131
3131
appGroupBy : key ,
3132
3132
}
3133
3133
}
3134
- row .TemplateIDs = append (row .TemplateIDs , row .TemplateIDs ... )
3134
+ row .TemplateIDs = uniqueSortedUUIDs ( append (row .TemplateIDs , aiRow .TemplateIDs ... ) )
3135
3135
templateRows [key ] = row
3136
3136
}
3137
3137
@@ -3171,18 +3171,20 @@ func (q *FakeQuerier) GetTemplateAppInsights(ctx context.Context, arg database.G
3171
3171
IsApp : aiRow .IsApp ,
3172
3172
}
3173
3173
row := groupedRows [key ]
3174
- row .TemplateIDs = append (row .TemplateIDs , aiRow .TemplateIDs ... )
3175
3174
row .ActiveUserIDs = append (row .ActiveUserIDs , aiRow .UserID )
3176
3175
row .UsageSeconds += aiRow .AppUsageMins * 60
3176
+ groupedRows [key ] = row
3177
3177
}
3178
3178
3179
3179
var rows []database.GetTemplateAppInsightsRow
3180
- for k , gr := range groupedRows {
3180
+ for key , gr := range groupedRows {
3181
3181
rows = append (rows , database.GetTemplateAppInsightsRow {
3182
- TemplateIDs : uniqueSortedUUIDs ( gr .TemplateIDs ) ,
3182
+ TemplateIDs : templateRows [ key ] .TemplateIDs ,
3183
3183
ActiveUsers : int64 (len (uniqueSortedUUIDs (gr .ActiveUserIDs ))),
3184
- DisplayName : k .DisplayName ,
3185
- SlugOrPort : k .AppName ,
3184
+ SlugOrPort : key .AppName ,
3185
+ DisplayName : key .DisplayName ,
3186
+ Icon : key .Icon ,
3187
+ IsApp : key .IsApp ,
3186
3188
UsageSeconds : gr .UsageSeconds ,
3187
3189
})
3188
3190
}
@@ -8354,7 +8356,7 @@ func (q *FakeQuerier) UpsertTemplateUsageStats(ctx context.Context) error {
8354
8356
return err
8355
8357
}
8356
8358
// CROSS JOIN generate_series
8357
- for t := was .SessionStartedAt ; t .Before (was .SessionEndedAt ); t = t .Add (time .Minute ) {
8359
+ for t := was .SessionStartedAt . Truncate ( time . Minute ) ; t .Before (was .SessionEndedAt ); t = t .Add (time .Minute ) {
8358
8360
// WHERE
8359
8361
if t .Before (latestStart ) || t .After (now ) || t .Equal (now ) {
8360
8362
continue
0 commit comments