Commit 2a93567b authored by Vincent Pelletier's avatar Vincent Pelletier

Make SQL(Queue|Dict)_getPriority use index more efficiently.

For some reason, MIN() doesn't use the index, while ORDER BY + LIMIT does.
Also, provide a more helpful error when assertion fails.
parent 8e01f703
...@@ -132,11 +132,10 @@ class SQLBase(Queue): ...@@ -132,11 +132,10 @@ class SQLBase(Queue):
def _getPriority(self, activity_tool, method, default): def _getPriority(self, activity_tool, method, default):
result = method() result = method()
assert len(result) == 1 if not result:
priority = result[0]['priority'] return default
if priority is None: assert len(result) == 1, len(result)
priority = default return result[0]['priority']
return priority
def _retryOnLockError(self, method, args=(), kw={}): def _retryOnLockError(self, method, args=(), kw={}):
while True: while True:
......
...@@ -9,9 +9,10 @@ class_file: ...@@ -9,9 +9,10 @@ class_file:
</dtml-comment> </dtml-comment>
<params> <params>
</params> </params>
SELECT MIN(`priority`) AS `priority` FROM SELECT `priority` FROM
message message
WHERE WHERE
processing_node = 0 processing_node = 0
AND date <= UTC_TIMESTAMP() AND date <= UTC_TIMESTAMP()
ORDER BY priority
LIMIT 1
...@@ -9,9 +9,10 @@ class_file: ...@@ -9,9 +9,10 @@ class_file:
</dtml-comment> </dtml-comment>
<params> <params>
</params> </params>
SELECT MIN(`priority`) AS `priority` FROM SELECT `priority` FROM
message_queue message_queue
WHERE WHERE
processing_node = 0 processing_node = 0
AND date <= UTC_TIMESTAMP() AND date <= UTC_TIMESTAMP()
ORDER BY priority
LIMIT 1
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