summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-06-23 17:50:30 +0100
committerErik Johnston <erik@matrix.org>2016-06-23 17:50:30 +0100
commit9df5f8168705cdb855829a6e2c1a459560f1e85c (patch)
treecce371605f37eff015452fae168c9300fb10505f
parentUse SyncExtras (diff)
downloadsynapse-9df5f8168705cdb855829a6e2c1a459560f1e85c.tar.xz
Make get_room_tags_changed take a now position. Comments
-rw-r--r--synapse/handlers/sync.py15
-rw-r--r--synapse/storage/tags.py12
2 files changed, 23 insertions, 4 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index 06ffb9040c..f068814e5d 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -827,7 +827,10 @@ class SyncHandler(object):
 
             if sync_result_builder.since_token:
                 stream_id = sync_result_builder.since_token.account_data_key
-                tag_changes = yield self.store.get_room_tags_changed(user_id, stream_id)
+                now_stream_id = sync_result_builder.now_token.account_data_key
+                tag_changes = yield self.store.get_room_tags_changed(
+                    user_id, stream_id, now_stream_id
+                )
             else:
                 tag_changes = {}
 
@@ -1207,6 +1210,8 @@ class SyncHandler(object):
         if not (always_include or batch or account_data or ephemeral):
             return
 
+        # At this point we're guarenteed (?) to send down the room, so if we
+        # need to resync the entire room do so now.
         if room_builder.would_require_resync:
             batch = yield self._load_filtered_recents(
                 room_id, sync_config,
@@ -1257,6 +1262,11 @@ class SyncHandler(object):
 
     @defer.inlineCallbacks
     def _get_room_timestamps_at_token(self, room_ids, token, sync_config, limit):
+        """For each room, get the last origin_server_ts timestamp the client
+        would see (after filtering) at a particular token.
+
+        Only attempts finds the latest `limit` room timestamps.
+        """
         room_to_entries = {}
 
         @defer.inlineCallbacks
@@ -1317,6 +1327,9 @@ class SyncHandler(object):
     @defer.inlineCallbacks
     def _get_rooms_that_need_full_state(self, room_ids, sync_config, since_token,
                                         pagination_state):
+        """Work out which rooms we haven't sent to the client yet, so would
+        require us to send down the full state
+        """
         start_ts = yield self._get_room_timestamps_at_token(
             room_ids, since_token,
             sync_config=sync_config,
diff --git a/synapse/storage/tags.py b/synapse/storage/tags.py
index 682576fb8d..8dcbe9bc90 100644
--- a/synapse/storage/tags.py
+++ b/synapse/storage/tags.py
@@ -176,7 +176,13 @@ class TagsStore(SQLBaseStore):
             row["tag"]: json.loads(row["content"]) for row in rows
         })
 
-    def get_room_tags_changed(self, user_id, stream_id):
+    def get_room_tags_changed(self, user_id, stream_id, now_id):
+        """Returns the rooms that have been newly tagged or had all their tags
+        removed since `stream_id`.
+
+        Collapses multiple changes into one. For example, if a room has gone
+        from untagged to tagged back to untagged, the room_id won't be returned.
+        """
         changed = self._account_data_stream_cache.has_entity_changed(
             user_id, int(stream_id)
         )
@@ -187,8 +193,8 @@ class TagsStore(SQLBaseStore):
         def _get_room_tags_changed(txn):
             txn.execute(
                 "SELECT room_id, change FROM room_tags_change_revisions"
-                " WHERE user_id = ? AND stream_id > ?",
-                (user_id, stream_id)
+                " WHERE user_id = ? AND stream_id > ? AND stream_id <= ?",
+                (user_id, stream_id, now_id)
             )
 
             results = Counter()