Skip to content

Commit 534a2cf

Browse files
committed
[usage] Exclude workspace instances without a startedTime
1 parent 6b14c1e commit 534a2cf

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

components/usage/pkg/db/workspace_instance.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ func ListWorkspaceInstancesInRange(ctx context.Context, conn *gorm.DB, from, to
134134
Where(
135135
conn.Where("wsi.stoppingTime >= ?", TimeToISO8601(from)).Or("wsi.stoppingTime = ?", ""),
136136
).
137-
Where("wsi.startedTime != ?", "").
138137
Where("wsi.startedTime < ?", TimeToISO8601(to)).
139138
Where("wsi.usageAttributionId != ?", "").
140139
FindInBatches(&instancesInBatch, 1000, func(_ *gorm.DB, _ int) error {
@@ -151,17 +150,19 @@ func ListWorkspaceInstancesInRange(ctx context.Context, conn *gorm.DB, from, to
151150
func queryWorkspaceInstanceForUsage(ctx context.Context, conn *gorm.DB) *gorm.DB {
152151
return conn.WithContext(ctx).
153152
Table(fmt.Sprintf("%s as wsi", (&WorkspaceInstance{}).TableName())).
154-
Select("wsi.id as id, " +
155-
"ws.projectId as projectId, " +
156-
"ws.type as workspaceType, " +
157-
"wsi.workspaceClass as workspaceClass, " +
158-
"wsi.usageAttributionId as usageAttributionId, " +
159-
"wsi.startedTime as startedTime, " +
160-
"wsi.stoppingTime as stoppingTime, " +
161-
"ws.ownerId as ownerId, " +
153+
Select("wsi.id as id, "+
154+
"ws.projectId as projectId, "+
155+
"ws.type as workspaceType, "+
156+
"wsi.workspaceClass as workspaceClass, "+
157+
"wsi.usageAttributionId as usageAttributionId, "+
158+
"wsi.startedTime as startedTime, "+
159+
"wsi.stoppingTime as stoppingTime, "+
160+
"ws.ownerId as ownerId, "+
162161
"ws.id as workspaceId",
163162
).
164-
Joins(fmt.Sprintf("LEFT JOIN %s AS ws ON wsi.workspaceId = ws.id", (&Workspace{}).TableName()))
163+
Joins(fmt.Sprintf("LEFT JOIN %s AS ws ON wsi.workspaceId = ws.id", (&Workspace{}).TableName())).
164+
// Instances without a StartedTime never actually started, we're not interested in these.
165+
Where("wsi.startedTime != ?", "")
165166
}
166167

167168
const (

0 commit comments

Comments
 (0)