@@ -2418,17 +2418,18 @@ func (q *FakeQuerier) GetTemplateInsightsByInterval(ctx context.Context, arg dat
2418
2418
q .mutex .RLock ()
2419
2419
defer q .mutex .RUnlock ()
2420
2420
2421
- type dailyStat struct {
2421
+ type statByInterval struct {
2422
2422
startTime , endTime time.Time
2423
2423
userSet map [uuid.UUID ]struct {}
2424
2424
templateIDSet map [uuid.UUID ]struct {}
2425
2425
}
2426
- dailyStats := []dailyStat {{arg .StartTime , arg .StartTime .AddDate (0 , 0 , 1 ), make (map [uuid.UUID ]struct {}), make (map [uuid.UUID ]struct {})}}
2427
- for dailyStats [len (dailyStats )- 1 ].endTime .Before (arg .EndTime ) {
2428
- dailyStats = append (dailyStats , dailyStat {dailyStats [len (dailyStats )- 1 ].endTime , dailyStats [len (dailyStats )- 1 ].endTime .AddDate (0 , 0 , 1 ), make (map [uuid.UUID ]struct {}), make (map [uuid.UUID ]struct {})})
2426
+
2427
+ statsByInterval := []statByInterval {{arg .StartTime , arg .StartTime .Add (arg .Interval ), make (map [uuid.UUID ]struct {}), make (map [uuid.UUID ]struct {})}}
2428
+ for statsByInterval [len (statsByInterval )- 1 ].endTime .Before (arg .EndTime ) {
2429
+ statsByInterval = append (statsByInterval , statByInterval {statsByInterval [len (statsByInterval )- 1 ].endTime , statsByInterval [len (statsByInterval )- 1 ].endTime .Add (arg .Interval ), make (map [uuid.UUID ]struct {}), make (map [uuid.UUID ]struct {})})
2429
2430
}
2430
- if dailyStats [len (dailyStats )- 1 ].endTime .After (arg .EndTime ) {
2431
- dailyStats [len (dailyStats )- 1 ].endTime = arg .EndTime
2431
+ if statsByInterval [len (statsByInterval )- 1 ].endTime .After (arg .EndTime ) {
2432
+ statsByInterval [len (statsByInterval )- 1 ].endTime = arg .EndTime
2432
2433
}
2433
2434
2434
2435
for _ , s := range q .workspaceAgentStats {
@@ -2442,7 +2443,7 @@ func (q *FakeQuerier) GetTemplateInsightsByInterval(ctx context.Context, arg dat
2442
2443
continue
2443
2444
}
2444
2445
2445
- for _ , ds := range dailyStats {
2446
+ for _ , ds := range statsByInterval {
2446
2447
if s .CreatedAt .Before (ds .startTime ) || s .CreatedAt .Equal (ds .endTime ) || s .CreatedAt .After (ds .endTime ) {
2447
2448
continue
2448
2449
}
@@ -2461,7 +2462,7 @@ func (q *FakeQuerier) GetTemplateInsightsByInterval(ctx context.Context, arg dat
2461
2462
continue
2462
2463
}
2463
2464
2464
- for _ , ds := range dailyStats {
2465
+ for _ , ds := range statsByInterval {
2465
2466
// (was.session_started_at >= ts.from_ AND was.session_started_at < ts.to_)
2466
2467
// OR (was.session_ended_at > ts.from_ AND was.session_ended_at < ts.to_)
2467
2468
// OR (was.session_started_at < ts.from_ AND was.session_ended_at >= ts.to_)
@@ -2477,7 +2478,7 @@ func (q *FakeQuerier) GetTemplateInsightsByInterval(ctx context.Context, arg dat
2477
2478
}
2478
2479
2479
2480
var result []database.GetTemplateInsightsByIntervalRow
2480
- for _ , ds := range dailyStats {
2481
+ for _ , ds := range statsByInterval {
2481
2482
templateIDs := make ([]uuid.UUID , 0 , len (ds .templateIDSet ))
2482
2483
for templateID := range ds .templateIDSet {
2483
2484
templateIDs = append (templateIDs , templateID )
0 commit comments