Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Make get_new_messages_txn SQL easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Nov 8, 2021
1 parent efd9634 commit d9f3249
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions synapse/storage/databases/main/deviceinbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,20 @@ async def get_new_messages(
def get_new_messages_txn(txn: LoggingTransaction):
# Build a query to select messages from any of the given users that are between
# the given stream id bounds
sql = "SELECT stream_id, user_id, device_id, message_json FROM device_inbox"

# Scope to only the given users. We need to use this method as doing so is
# different across database engines.
many_clause_sql, many_clause_args = make_in_list_sql_clause(
self.database_engine, "user_id", user_ids
)

sql += (
" WHERE %s"
" AND ? < stream_id AND stream_id <= ?"
" ORDER BY stream_id ASC"
" LIMIT ?"
) % many_clause_sql
sql = f"""
SELECT stream_id, user_id, device_id, message_json FROM device_inbox
WHERE {many_clause_sql}
AND ? < stream_id AND stream_id <= ?
ORDER BY stream_id ASC
LIMIT ?
"""

txn.execute(sql, (*many_clause_args, from_stream_id, to_stream_id, limit))

Expand Down

0 comments on commit d9f3249

Please sign in to comment.