mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix: Sort workspace by name by created_at (#2214)
* fix: Sort workspace by name by created_at Fix bug where deleting workspaces with the same name returns the oldest deleted workspace
This commit is contained in:
@ -375,7 +375,9 @@ func (q *fakeQuerier) GetWorkspaceByOwnerIDAndName(_ context.Context, arg databa
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
var found *database.Workspace
|
||||
for _, workspace := range q.workspaces {
|
||||
workspace := workspace
|
||||
if workspace.OwnerID != arg.OwnerID {
|
||||
continue
|
||||
}
|
||||
@ -385,7 +387,14 @@ func (q *fakeQuerier) GetWorkspaceByOwnerIDAndName(_ context.Context, arg databa
|
||||
if workspace.Deleted != arg.Deleted {
|
||||
continue
|
||||
}
|
||||
return workspace, nil
|
||||
|
||||
// Return the most recent workspace with the given name
|
||||
if found == nil || workspace.CreatedAt.After(found.CreatedAt) {
|
||||
found = &workspace
|
||||
}
|
||||
}
|
||||
if found != nil {
|
||||
return *found, nil
|
||||
}
|
||||
return database.Workspace{}, sql.ErrNoRows
|
||||
}
|
||||
|
Reference in New Issue
Block a user