Reduce hot run polling pressure
This commit is contained in:
@@ -486,6 +486,39 @@ func newMemoryJobRepository() *memoryJobRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (repository *memoryJobRepository) List(filter domain.JobFilter) ([]domain.Job, error) {
|
||||
if filter.Limit <= 0 {
|
||||
return repository.memoryRepository.List(filter)
|
||||
}
|
||||
|
||||
repository.mu.RLock()
|
||||
defer repository.mu.RUnlock()
|
||||
|
||||
values := make([]domain.Job, 0, min(filter.Limit, len(repository.byID)))
|
||||
for _, job := range repository.byID {
|
||||
if repository.match(job, filter) {
|
||||
values = append(values, domain.CopyJob(job))
|
||||
}
|
||||
}
|
||||
sort.SliceStable(values, func(i, j int) bool {
|
||||
leftUpdated := values[i].UpdatedAt
|
||||
rightUpdated := values[j].UpdatedAt
|
||||
if !leftUpdated.Equal(rightUpdated) {
|
||||
return leftUpdated.After(rightUpdated)
|
||||
}
|
||||
leftCreated := values[i].CreatedAt
|
||||
rightCreated := values[j].CreatedAt
|
||||
if !leftCreated.Equal(rightCreated) {
|
||||
return leftCreated.After(rightCreated)
|
||||
}
|
||||
return values[i].ID < values[j].ID
|
||||
})
|
||||
if len(values) > filter.Limit {
|
||||
values = values[:filter.Limit]
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
func (repository *memoryJobRepository) GetByIdempotency(runEndpointID string, idempotencyKey string) (domain.Job, error) {
|
||||
repository.mu.RLock()
|
||||
defer repository.mu.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user