|
81 | 81 | DatabasePool, |
82 | 82 | LoggingDatabaseConnection, |
83 | 83 | LoggingTransaction, |
| 84 | + make_tuple_in_list_sql_clause, |
84 | 85 | ) |
85 | 86 | from synapse.storage.types import Cursor |
86 | 87 | from synapse.storage.util.id_generators import ( |
@@ -1617,21 +1618,28 @@ def _fetch_event_rows( |
1617 | 1618 | # likely that some of these events may be for the same room/user combo, in |
1618 | 1619 | # which case we don't need to do redundant queries |
1619 | 1620 | to_check_set = set(to_check) |
1620 | | - for room_and_user in to_check_set: |
1621 | | - room_redactions_sql = "SELECT redacting_event_id, redact_end_ordering FROM room_ban_redactions WHERE room_id = ? and user_id = ?" |
1622 | | - txn.execute(room_redactions_sql, room_and_user) |
1623 | | - |
1624 | | - res = txn.fetchone() |
1625 | | - # we have a redaction for a room, user_id combo - apply it to matching events |
1626 | | - if not res: |
1627 | | - continue |
| 1621 | + room_redaction_sql = "SELECT room_id, user_id, redacting_event_id, redact_end_ordering FROM room_ban_redactions WHERE " |
| 1622 | + ( |
| 1623 | + in_list_clause, |
| 1624 | + room_redaction_args, |
| 1625 | + ) = make_tuple_in_list_sql_clause( |
| 1626 | + self.database_engine, ("room_id", "user_id"), to_check_set |
| 1627 | + ) |
| 1628 | + txn.execute(room_redaction_sql + in_list_clause, room_redaction_args) |
| 1629 | + for ( |
| 1630 | + returned_room_id, |
| 1631 | + returned_user_id, |
| 1632 | + redacting_event_id, |
| 1633 | + redact_end_ordering, |
| 1634 | + ) in txn: |
1628 | 1635 | for e_row in events: |
1629 | 1636 | e_json = json.loads(e_row.json) |
1630 | 1637 | room_id = e_json.get("room_id") |
1631 | 1638 | user_id = e_json.get("sender") |
| 1639 | + room_and_user = (returned_room_id, returned_user_id) |
| 1640 | + # check if we have a redaction match for this room, user combination |
1632 | 1641 | if room_and_user != (room_id, user_id): |
1633 | 1642 | continue |
1634 | | - redacting_event_id, redact_end_ordering = res |
1635 | 1643 | if redact_end_ordering: |
1636 | 1644 | # Avoid redacting any events arriving *after* the membership event which |
1637 | 1645 | # ends an active redaction - note that this will always redact |
|
0 commit comments