summary refs log tree commit diff
path: root/synapse/storage/events.py
diff options
context:
space:
mode:
authorLuke Barnard <lukebarnard1@users.noreply.github.com>2017-04-13 14:21:31 +0100
committerGitHub <noreply@github.com>2017-04-13 14:21:31 +0100
commit78f0ddbfadefd877b161094d467d4863bd8890f9 (patch)
treec3e0ed7ccb314c91486358398f6d9192527cf15a /synapse/storage/events.py
parentMerge pull request #2115 from matrix-org/erikj/dedupe_federation_repl (diff)
parentCorrect logic in is_event_after (diff)
downloadsynapse-78f0ddbfadefd877b161094d467d4863bd8890f9.tar.xz
Merge pull request #2120 from matrix-org/luke/read-markers
Implement Read Marker API
Diffstat (limited to 'synapse/storage/events.py')
-rw-r--r--synapse/storage/events.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 64fe937bdc..a3790419dd 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -2159,6 +2159,28 @@ class EventsStore(SQLBaseStore):
             ]
         )
 
+    @defer.inlineCallbacks
+    def is_event_after(self, event_id1, event_id2):
+        """Returns True if event_id1 is after event_id2 in the stream
+        """
+        to_1, so_1 = yield self._get_event_ordering(event_id1)
+        to_2, so_2 = yield self._get_event_ordering(event_id2)
+        defer.returnValue((to_1, so_1) > (to_2, so_2))
+
+    @defer.inlineCallbacks
+    def _get_event_ordering(self, event_id):
+        res = yield self._simple_select_one(
+            table="events",
+            retcols=["topological_ordering", "stream_ordering"],
+            keyvalues={"event_id": event_id},
+            allow_none=True
+        )
+
+        if not res:
+            raise SynapseError(404, "Could not find event %s" % (event_id,))
+
+        defer.returnValue((int(res["topological_ordering"]), int(res["stream_ordering"])))
+
 
 AllNewEventsResult = namedtuple("AllNewEventsResult", [
     "new_forward_events", "new_backfill_events",