Fix buglet and remove thread_id stuff
This commit is contained in:
parent
9accd63a38
commit
080025e533
|
@ -838,10 +838,9 @@ class TimestampLookupRestServlet(ClientV1RestServlet):
|
|||
yield self.auth.check_joined_room(room_id, requester.user.to_string())
|
||||
|
||||
timestamp = parse_integer(request, "ts")
|
||||
thread_id = parse_integer(request, "thread_id", 0)
|
||||
|
||||
event_id = yield self.store.get_event_for_timestamp(
|
||||
room_id, thread_id, timestamp,
|
||||
room_id, timestamp,
|
||||
)
|
||||
|
||||
defer.returnValue((200, {
|
||||
|
|
|
@ -527,33 +527,32 @@ class EventsWorkerStore(SQLBaseStore):
|
|||
|
||||
return self.runInteraction("get_rejection_reasons", f)
|
||||
|
||||
def get_event_for_timestamp(self, room_id, thread_id, timestamp):
|
||||
def get_event_for_timestamp(self, room_id, timestamp):
|
||||
sql_template = """
|
||||
SELECT event_id, origin_server_ts FROM events
|
||||
WHERE
|
||||
origin_server_ts %s ?
|
||||
AND room_id = ?
|
||||
AND thread_id = ?
|
||||
ORDER BY origin_server_ts
|
||||
LIMIT 1;
|
||||
"""
|
||||
|
||||
def f(txn):
|
||||
txn.execute(sql_template % ("<=",), (timestamp, room_id, thread_id))
|
||||
txn.execute(sql_template % ("<=",), (timestamp, room_id))
|
||||
row = txn.fetchone()
|
||||
if row:
|
||||
event_id_before, ts_before = row
|
||||
else:
|
||||
event_id_before, ts_before = None, None
|
||||
|
||||
txn.execute(sql_template % (">=",), (timestamp, room_id, thread_id))
|
||||
txn.execute(sql_template % (">=",), (timestamp, room_id))
|
||||
row = txn.fetchone()
|
||||
if row:
|
||||
event_id_after, ts_after = row
|
||||
else:
|
||||
event_id_after, ts_after = None, None
|
||||
|
||||
if event_id_before and event_id_before:
|
||||
if event_id_before and event_id_after:
|
||||
# Return the closest one
|
||||
if (timestamp - ts_before) < (ts_after - timestamp):
|
||||
return event_id_before
|
||||
|
|
Loading…
Reference in a new issue