Improve the performance of queue candidate queries.

This commit is contained in:
Jake Moshenko 2015-08-04 18:20:54 -04:00
parent af1d4e8dc8
commit ed62339f89

View file

@ -120,16 +120,21 @@ class WorkQueue(object):
name_match_query = self._name_match_query()
running = self._running_jobs(now, name_match_query)
avail = self._available_jobs_not_running(now, name_match_query, running)
avail = self._available_jobs_not_running(now, name_match_query, running).alias('avail')
item = None
try:
db_item_candidate = avail.order_by(QueueItem.id).get()
db_item_candidate_id = (QueueItem
.select(avail.c.id)
.from_(avail)
.order_by(avail.c.id)
.tuples()
.get())[0]
with self._transaction_factory(db):
still_available_query = (db_for_update(self
._available_jobs(now, name_match_query)
.where(QueueItem.id == db_item_candidate.id)))
.where(QueueItem.id == db_item_candidate_id)))
db_item = still_available_query.get()
db_item.available = False