Commit f49aeb9a authored by Andreas Brandl's avatar Andreas Brandl

Optimize count query

Only count up to the point we're interested in
parent 91868dbf
---
title: Limit count to improve query performance
merge_request: 12231
author:
type: performance
......@@ -37,11 +37,11 @@ module Gitlab
return false if available_spots < capacity_threshold
# Only reschedule if we are able to completely fill up the available spots.
mirrors_ready_to_sync_count >= available_spots
mirrors_ready_to_sync_count(available_spots + 1) >= available_spots
end
def mirrors_ready_to_sync_count
Project.mirrors_to_sync(Time.now).count
def mirrors_ready_to_sync_count(up_to = nil)
Project.mirrors_to_sync(Time.now).limit(up_to).count
end
def available_capacity
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment