memory (sqlite): fixed order for last_stanza_id:
"last_stanza_id" filter was ordered by "received_timestamp" instead of "timestamp", resulting in wrong message being used (and a bad MAM request).
This commit is contained in:
parent
31a9e2bd09
commit
59faac55fe
1 changed files with 6 additions and 12 deletions
|
|
@ -592,9 +592,6 @@ class SqliteStorage(object):
|
|||
q.append(test_jid('dest', to_jid))
|
||||
query_parts.append(u"AND " + u" AND ".join(q))
|
||||
|
||||
# set to True if "ORDER BY" is already added
|
||||
order = False
|
||||
|
||||
if filters:
|
||||
if u'timestamp_start' in filters:
|
||||
query_parts.append(u"AND timestamp>= ?")
|
||||
|
|
@ -618,20 +615,17 @@ class SqliteStorage(object):
|
|||
# this request get the last message with a "stanza_id" that we
|
||||
# have in history. This is mainly used to retrieve messages sent
|
||||
# while we were offline, using MAM (XEP-0313).
|
||||
# It must be set after all other filters, because it contains an ORDER BY
|
||||
if (filters[u'last_stanza_id'] is not True
|
||||
or limit != 1):
|
||||
raise ValueError(u"Unexpected values for last_stanza_id filter")
|
||||
query_parts.append(u"AND stanza_id IS NOT NULL ORDER BY history.received_timestamp DESC")
|
||||
order = True
|
||||
query_parts.append(u"AND stanza_id IS NOT NULL")
|
||||
|
||||
|
||||
if not order:
|
||||
# timestamp may be identical for 2 close messages (specially when delay is
|
||||
# used) that's why we order ties by received_timestamp
|
||||
# We'll reverse the order in sqliteHistoryToList
|
||||
query_parts.append(u"ORDER BY timestamp DESC, history.received_timestamp DESC")
|
||||
# we use DESC here so LIMIT keep the last messages
|
||||
# timestamp may be identical for 2 close messages (specially when delay is
|
||||
# used) that's why we order ties by received_timestamp
|
||||
# We'll reverse the order in sqliteHistoryToList
|
||||
# we use DESC here so LIMIT keep the last messages
|
||||
query_parts.append(u"ORDER BY timestamp DESC, history.received_timestamp DESC")
|
||||
if limit is not None:
|
||||
query_parts.append(u"LIMIT ?")
|
||||
values.append(limit)
|
||||
|
|
|
|||
Loading…
Reference in a new issue