getOldestPrebuildIDs returns the IDs of the N oldest prebuilds, sorted by creation time. This is used when we need to delete prebuilds, ensuring we remove the oldest ones first.
(n int)
| 470 | // getOldestPrebuildIDs returns the IDs of the N oldest prebuilds, sorted by creation time. |
| 471 | // This is used when we need to delete prebuilds, ensuring we remove the oldest ones first. |
| 472 | func (p PresetSnapshot) getOldestPrebuildIDs(n int) []uuid.UUID { |
| 473 | // Sort by creation time, oldest first |
| 474 | slices.SortFunc(p.Running, func(a, b database.GetRunningPrebuiltWorkspacesRow) int { |
| 475 | return a.CreatedAt.Compare(b.CreatedAt) |
| 476 | }) |
| 477 | |
| 478 | // Take the first N IDs |
| 479 | n = min(n, len(p.Running)) |
| 480 | ids := make([]uuid.UUID, n) |
| 481 | for i := 0; i < n; i++ { |
| 482 | ids[i] = p.Running[i].ID |
| 483 | } |
| 484 | |
| 485 | return ids |
| 486 | } |
no test coverage detected