diff options
author | Richard van der Hoff <richard@matrix.org> | 2019-06-05 16:32:35 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2019-06-05 16:32:35 +0100 |
commit | 7603a706eb96305d804da05030a71288fcc255ab (patch) | |
tree | d59bcc7827bc6b038d5c3e7bc46677a84007e255 /synapse/storage | |
parent | Update sample config (diff) | |
parent | Fix `federation_custom_ca_list` configuration option. (diff) | |
download | synapse-7603a706eb96305d804da05030a71288fcc255ab.tar.xz |
Merge branch 'rav/fix_custom_ca' into rav/enable_tls_verification
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/events_worker.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/synapse/storage/events_worker.py b/synapse/storage/events_worker.py index 1782428048..cc7df5cf14 100644 --- a/synapse/storage/events_worker.py +++ b/synapse/storage/events_worker.py @@ -78,6 +78,43 @@ class EventsWorkerStore(SQLBaseStore): desc="get_received_ts", ) + def get_received_ts_by_stream_pos(self, stream_ordering): + """Given a stream ordering get an approximate timestamp of when it + happened. + + This is done by simply taking the received ts of the first event that + has a stream ordering greater than or equal to the given stream pos. + If none exists returns the current time, on the assumption that it must + have happened recently. + + Args: + stream_ordering (int) + + Returns: + Deferred[int] + """ + + def _get_approximate_received_ts_txn(txn): + sql = """ + SELECT received_ts FROM events + WHERE stream_ordering >= ? + LIMIT 1 + """ + + txn.execute(sql, (stream_ordering,)) + row = txn.fetchone() + if row and row[0]: + ts = row[0] + else: + ts = self.clock.time_msec() + + return ts + + return self.runInteraction( + "get_approximate_received_ts", + _get_approximate_received_ts_txn, + ) + @defer.inlineCallbacks def get_event( self, |