mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
fix(coderd): workspaceapps: update last_used_at when workspace app reports stats (#11603)
- Adds a new query BatchUpdateLastUsedAt - Adds calls to BatchUpdateLastUsedAt in app stats handler upon flush - Passes a stats flush channel to apptest setup scaffolding and updates unit tests to assert modifications to LastUsedAt.
This commit is contained in:
@ -963,6 +963,31 @@ func (q *FakeQuerier) ArchiveUnusedTemplateVersions(_ context.Context, arg datab
|
||||
return archived, nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) BatchUpdateWorkspaceLastUsedAt(_ context.Context, arg database.BatchUpdateWorkspaceLastUsedAtParams) error {
|
||||
err := validateDatabaseType(arg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
// temporary map to avoid O(q.workspaces*arg.workspaceIds)
|
||||
m := make(map[uuid.UUID]struct{})
|
||||
for _, id := range arg.IDs {
|
||||
m[id] = struct{}{}
|
||||
}
|
||||
n := 0
|
||||
for i := 0; i < len(q.workspaces); i++ {
|
||||
if _, found := m[q.workspaces[i].ID]; !found {
|
||||
continue
|
||||
}
|
||||
q.workspaces[i].LastUsedAt = arg.LastUsedAt
|
||||
n++
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*FakeQuerier) CleanTailnetCoordinators(_ context.Context) error {
|
||||
return ErrUnimplemented
|
||||
}
|
||||
|
Reference in New Issue
Block a user