Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Only return new device messages in /sync #1066

Merged
merged 1 commit into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def _generate_sync_entry_for_to_device(self, sync_result_builder):

logger.debug("Getting messages up to %d", now_token.to_device_key)
messages, stream_id = yield self.store.get_new_messages_for_device(
user_id, device_id, now_token.to_device_key
user_id, device_id, since_stream_id, now_token.to_device_key
)
logger.debug("Got messages up to %d: %r", stream_id, messages)
sync_result_builder.now_token = now_token.copy_and_replace(
Expand Down
8 changes: 5 additions & 3 deletions synapse/storage/deviceinbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def add_messages_to_device_inbox_txn(txn, stream_id):
defer.returnValue(self._device_inbox_id_gen.get_current_token())

def get_new_messages_for_device(
self, user_id, device_id, current_stream_id, limit=100
self, user_id, device_id, last_stream_id, current_stream_id, limit=100
):
"""
Args:
Expand All @@ -101,11 +101,13 @@ def get_new_messages_for_device_txn(txn):
sql = (
"SELECT stream_id, message_json FROM device_inbox"
" WHERE user_id = ? AND device_id = ?"
" AND stream_id <= ?"
" AND ? < stream_id AND stream_id <= ?"
" ORDER BY stream_id ASC"
" LIMIT ?"
)
txn.execute(sql, (user_id, device_id, current_stream_id, limit))
txn.execute(sql, (
user_id, device_id, last_stream_id, current_stream_id, limit
))
messages = []
for row in txn.fetchall():
stream_pos = row[0]
Expand Down