Fix active index's order

Message Controller's active index is not ordere correctly. Since we're
using K for sorting operation, it should be in the second position right
after the equality filters' indexes ('q'). This is necessary because
MongoDB sorts everything before applying range filters ('e', 'c.e') and
compound indexes are traversed in order. Without this patch, mongodb
would filter records and then sort them in memory w/o using the index.

Fixes bug: #1206517

Change-Id: I54ac464ce849f2dcde92a96090c27c489ea80e97
This commit is contained in:
Flaper Fesp 2013-07-31 13:17:40 +02:00
parent 70a3ab6ba1
commit cef36a25fb

View File

@ -70,14 +70,14 @@ class MessageController(storage.MessageBase):
# other places.
# * q: Mostly everywhere. It must stay at the
# beginning of the index.
# * k: Marker and FIFO key (Used mainly for sorting)
# * e: Together with q is used for getting a
# specific message. (see `get`)
self.active_fields = [
('q', 1),
('k', 1),
('e', 1),
('c.e', 1),
('k', 1),
('_id', -1),
]
self._col.ensure_index(self.active_fields,