@@ -10,11 +10,11 @@ import (
10
10
11
11
// GlobalSnapshot represents a full point-in-time snapshot of state relating to prebuilds across all templates.
12
12
type GlobalSnapshot struct {
13
- Presets []database.GetTemplatePresetsWithPrebuildsRow
14
- RunningPrebuilds []database.GetRunningPrebuiltWorkspacesRow
15
- PrebuildsInProgress []database.CountInProgressPrebuildsRow
16
- Backoffs []database.GetPresetsBackoffRow
17
- HardLimitedPresetMap map [uuid. UUID ]database.GetPresetsAtFailureLimitRow
13
+ Presets []database.GetTemplatePresetsWithPrebuildsRow
14
+ RunningPrebuilds []database.GetRunningPrebuiltWorkspacesRow
15
+ PrebuildsInProgress []database.CountInProgressPrebuildsRow
16
+ Backoffs []database.GetPresetsBackoffRow
17
+ HardLimitedPresets [ ]database.GetPresetsAtFailureLimitRow
18
18
}
19
19
20
20
func NewGlobalSnapshot (
@@ -24,17 +24,12 @@ func NewGlobalSnapshot(
24
24
backoffs []database.GetPresetsBackoffRow ,
25
25
hardLimitedPresets []database.GetPresetsAtFailureLimitRow ,
26
26
) GlobalSnapshot {
27
- hardLimitedPresetMap := make (map [uuid.UUID ]database.GetPresetsAtFailureLimitRow , len (hardLimitedPresets ))
28
- for _ , preset := range hardLimitedPresets {
29
- hardLimitedPresetMap [preset .PresetID ] = preset
30
- }
31
-
32
27
return GlobalSnapshot {
33
- Presets : presets ,
34
- RunningPrebuilds : runningPrebuilds ,
35
- PrebuildsInProgress : prebuildsInProgress ,
36
- Backoffs : backoffs ,
37
- HardLimitedPresetMap : hardLimitedPresetMap ,
28
+ Presets : presets ,
29
+ RunningPrebuilds : runningPrebuilds ,
30
+ PrebuildsInProgress : prebuildsInProgress ,
31
+ Backoffs : backoffs ,
32
+ HardLimitedPresets : hardLimitedPresets ,
38
33
}
39
34
}
40
35
@@ -65,15 +60,15 @@ func (s GlobalSnapshot) FilterByPreset(presetID uuid.UUID) (*PresetSnapshot, err
65
60
backoffPtr = & backoff
66
61
}
67
62
63
+ _ , isHardLimited := slice .Find (s .HardLimitedPresets , func (row database.GetPresetsAtFailureLimitRow ) bool {
64
+ return row .PresetID == preset .ID
65
+ })
66
+
68
67
return & PresetSnapshot {
69
- Preset : preset ,
70
- Running : running ,
71
- InProgress : inProgress ,
72
- Backoff : backoffPtr ,
68
+ Preset : preset ,
69
+ Running : running ,
70
+ InProgress : inProgress ,
71
+ Backoff : backoffPtr ,
72
+ IsHardLimited : isHardLimited ,
73
73
}, nil
74
74
}
75
-
76
- func (s GlobalSnapshot ) IsHardLimited (presetID uuid.UUID ) bool {
77
- _ , ok := s .HardLimitedPresetMap [presetID ]
78
- return ok
79
- }
0 commit comments