[BUG] Add early-return to loading items from SpecList

- Add an early-return to `LoadSchedules` and `LoadRepos` of the
`SpecList` type, @Beowulf noticed that useless queries were being run
every 30 seconds. These stemmed from these two functions being run even
if there were no scheduled actions.
- No tests were added, because there is zero testing infrastructure or
fixtures for the actions specifications models. I feel these are trivial
enough to not require any tests.
This commit is contained in:
Gusted 2024-07-20 01:24:34 +02:00
parent 2d3b7ae939
commit f7dac2c3d9
No known key found for this signature in database
GPG key ID: FD821B732837125F

View file

@ -22,6 +22,10 @@ func (specs SpecList) GetScheduleIDs() []int64 {
} }
func (specs SpecList) LoadSchedules(ctx context.Context) error { func (specs SpecList) LoadSchedules(ctx context.Context) error {
if len(specs) == 0 {
return nil
}
scheduleIDs := specs.GetScheduleIDs() scheduleIDs := specs.GetScheduleIDs()
schedules, err := GetSchedulesMapByIDs(ctx, scheduleIDs) schedules, err := GetSchedulesMapByIDs(ctx, scheduleIDs)
if err != nil { if err != nil {
@ -50,6 +54,10 @@ func (specs SpecList) GetRepoIDs() []int64 {
} }
func (specs SpecList) LoadRepos(ctx context.Context) error { func (specs SpecList) LoadRepos(ctx context.Context) error {
if len(specs) == 0 {
return nil
}
repoIDs := specs.GetRepoIDs() repoIDs := specs.GetRepoIDs()
repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs) repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs)
if err != nil { if err != nil {