Merge pull request #309 from coreos-inc/fasterqueue
Improve the performance of queue candidate queries.
This commit is contained in:
commit
ee53c04a45
1 changed files with 8 additions and 3 deletions
|
@ -120,16 +120,21 @@ class WorkQueue(object):
|
||||||
name_match_query = self._name_match_query()
|
name_match_query = self._name_match_query()
|
||||||
|
|
||||||
running = self._running_jobs(now, 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
|
item = None
|
||||||
try:
|
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):
|
with self._transaction_factory(db):
|
||||||
still_available_query = (db_for_update(self
|
still_available_query = (db_for_update(self
|
||||||
._available_jobs(now, name_match_query)
|
._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 = still_available_query.get()
|
||||||
db_item.available = False
|
db_item.available = False
|
||||||
|
|
Reference in a new issue