Commit 1ac852f0 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Logger: Improve speed of find_stanza_id()

The SQLite Query Planner does not use the best index
parent 7137b37e
......@@ -1405,10 +1405,14 @@ def find_stanza_id(self, account, archive_jid, stanza_id, origin_id=None,
# Stanza ID is only unique within a specific archive.
# So a Stanza ID could be repeated in different MUCs, so we
# filter also for the archive JID which is the bare MUC jid.
# Use Unary-"+" operator for "jid_id", otherwise the
# idx_logs_jid_id_time index is used instead of the much better
# idx_logs_stanza_id index
sql = '''
SELECT stanza_id FROM logs
WHERE stanza_id IN ({values})
AND jid_id = ? AND account_id = ? LIMIT 1
AND +jid_id = ? AND account_id = ? LIMIT 1
'''.format(values=', '.join('?' * len(ids)))
result = self._con.execute(
sql, tuple(ids) + (archive_id, account_id)).fetchone()
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