fix(mongodb): Remove $or clause used to claim messages

The $or clause was removed from one of the queries in
ClaimController.create() because it is no longer necessary,
and makes the query slower than it would otherwise be.

Mongo will just use the _id_ index now, which should be fine
since scanning a small set of messages by c.e is fast.

Change-Id: Ifcb918ef66d072a10690ad49406f4a787e84becd
Implements: blueprint bp/api-perf-tuning
This commit is contained in:
kgriffs 2013-09-20 10:16:41 -05:00
parent e96cee8b97
commit fb4b34d0ee

View File

@ -151,15 +151,19 @@ class ClaimController(storage.ClaimBase):
now = timeutils.utcnow_ts()
# Set claim field for messages in ids
# NOTE(kgriffs): Set the claim field for
# the active message batch, while also
# filtering out any messages that happened
# to get claimed just now by one or more
# parallel requests.
#
# Filtering by just 'c.e' works because
# new messages have that field initialized
# to the current time when the message is
# posted. There is no need to check whether
# 'c' exists or 'c.id' is None.
updated = msg_ctrl._col.update({'_id': {'$in': ids},
'$or': [
{'c.id': None},
{
'c.id': {'$ne': None},
'c.e': {'$lte': now}
}
]},
'c.e': {'$lte': now}},
{'$set': {'c': meta}}, upsert=False,
multi=True)['n']