summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-06-01 11:19:57 +0100
committerErik Johnston <erik@matrix.org>2018-06-01 11:19:57 +0100
commit47b36e9a02e0b1d56f39e6e981bfd0a51b4ea0fc (patch)
treef6601c87d4603aa4fa3c24743389732a07e4dfa9
parentImplement pagination using chunks (diff)
downloadsynapse-47b36e9a02e0b1d56f39e6e981bfd0a51b4ea0fc.tar.xz
Update docs for RoomStreamToken
-rw-r--r--synapse/types.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/synapse/types.py b/synapse/types.py
index 27f204ce79..1ff71aa4e2 100644
--- a/synapse/types.py
+++ b/synapse/types.py
@@ -306,7 +306,7 @@ StreamToken.START = StreamToken(
 )
 
 
-class RoomStreamToken(namedtuple("_StreamToken", "chunk topological stream")):
+class RoomStreamToken(namedtuple("_StreamToken", ("chunk", "topological", "stream"))):
     """Tokens are positions between events. The token "s1" comes after event 1.
 
             s0    s1
@@ -319,14 +319,18 @@ class RoomStreamToken(namedtuple("_StreamToken", "chunk topological stream")):
     When traversing the live event stream events are ordered by when they
     arrived at the homeserver.
 
-    When traversing historic events the events are ordered by their depth in
-    the event graph "topological_ordering" and then by when they arrived at the
-    homeserver "stream_ordering".
+    When traversing historic events the events are ordered by the topological
+    ordering of the room graph. This is done using event chunks and the
+    `topological_ordering` column.
 
-    Live tokens start with an "s" followed by the "stream_ordering" id of the
-    event it comes after. Historic tokens start with a "t" followed by the
-    "topological_ordering" id of the event it comes after, followed by "-",
-    followed by the "stream_ordering" id of the event it comes after.
+    Live tokens start with an 's' and include the stream_ordering of the event
+    it comes after. Historic tokens start with a 'c' and include the chunk ID,
+    topological ordering and stream ordering of the event it comes after.
+
+    (In previous versions, when chunks were not implemented, the historic tokens
+    started with 't' and included the topological and stream ordering. These
+    tokens can be roughly converted to the new format by looking up the chunk
+    and topological ordering of the event with the same stream ordering).
     """
     __slots__ = []
 
@@ -339,6 +343,8 @@ class RoomStreamToken(namedtuple("_StreamToken", "chunk topological stream")):
                 parts = string[1:].split('-', 1)
                 return cls(chunk=None, topological=int(parts[0]), stream=int(parts[1]))
             if string[0] == 'c':
+                # We use '~' as both stream ordering and topological ordering
+                # can be negative, so we can't use '-'
                 parts = string[1:].split('~', 2)
                 return cls(
                     chunk=int(parts[0]),
@@ -360,6 +366,8 @@ class RoomStreamToken(namedtuple("_StreamToken", "chunk topological stream")):
 
     def __str__(self):
         if self.chunk is not None:
+            # We use '~' as both stream ordering and topological ordering
+            # can be negative, so we can't use '-'
             return "c%d~%d~%d" % (self.chunk, self.topological, self.stream)
         if self.topological is not None:
             return "t%d-%d" % (self.topological, self.stream)