data.queue: limiting before order by rand
This commit is contained in:
parent
fdf49d65ec
commit
8a5aa65d74
1 changed files with 5 additions and 6 deletions
|
@ -155,12 +155,11 @@ class WorkQueue(object):
|
||||||
avail = self._available_jobs_not_running(now, name_match_query, running)
|
avail = self._available_jobs_not_running(now, name_match_query, running)
|
||||||
db_item = avail.order_by(QueueItem.id).get()
|
db_item = avail.order_by(QueueItem.id).get()
|
||||||
else:
|
else:
|
||||||
# If we don't require ordering, we can forego this whole subquery and
|
# If we don't require ordering, we grab a random item from any of the first 50 available.
|
||||||
# instead try and grab any available item. We ORDER BY randomly in order
|
subquery = self._available_jobs(now, name_match_query).limit(50).alias('j1')
|
||||||
# to prevent races.
|
db_item = (QueueItem
|
||||||
db_item = (self
|
.select()
|
||||||
._available_jobs(now, name_match_query)
|
.join(subquery, on=QueueItem.id == subquery.c.id)
|
||||||
.limit(50)
|
|
||||||
.order_by(db_random_func())
|
.order_by(db_random_func())
|
||||||
.get())
|
.get())
|
||||||
|
|
||||||
|
|
Reference in a new issue