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

Commit

Permalink
Remove old populate current_state_events membership background job
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Sep 7, 2022
1 parent 875877c commit 409ef7b
Showing 1 changed file with 0 additions and 68 deletions.
68 changes: 0 additions & 68 deletions synapse/storage/databases/main/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@


_MEMBERSHIP_PROFILE_UPDATE_NAME = "room_membership_profile_update"
_CURRENT_STATE_MEMBERSHIP_UPDATE_NAME = "current_state_events_membership"


@attr.s(frozen=True, slots=True, auto_attribs=True)
Expand Down Expand Up @@ -1255,10 +1254,6 @@ def __init__(
self.db_pool.updates.register_background_update_handler(
_MEMBERSHIP_PROFILE_UPDATE_NAME, self._background_add_membership_profile
)
self.db_pool.updates.register_background_update_handler(
_CURRENT_STATE_MEMBERSHIP_UPDATE_NAME,
self._background_current_state_membership,
)
self.db_pool.updates.register_background_index_update(
"room_membership_forgotten_idx",
index_name="room_memberships_user_room_forgotten",
Expand Down Expand Up @@ -1341,69 +1336,6 @@ def add_membership_profile_txn(txn: LoggingTransaction) -> int:

return result

async def _background_current_state_membership(
self, progress: JsonDict, batch_size: int
) -> int:
"""Update the new membership column on current_state_events.
This works by iterating over all rooms in alphebetical order.
"""

def _background_current_state_membership_txn(
txn: LoggingTransaction, last_processed_room: str
) -> Tuple[int, bool]:
processed = 0
while processed < batch_size:
txn.execute(
"""
SELECT MIN(room_id) FROM current_state_events WHERE room_id > ?
""",
(last_processed_room,),
)
row = txn.fetchone()
if not row or not row[0]:
return processed, True

(next_room,) = row

sql = """
UPDATE current_state_events
SET membership = (
SELECT membership FROM room_memberships
WHERE event_id = current_state_events.event_id
)
WHERE room_id = ?
"""
txn.execute(sql, (next_room,))
processed += txn.rowcount

last_processed_room = next_room

self.db_pool.updates._background_update_progress_txn(
txn,
_CURRENT_STATE_MEMBERSHIP_UPDATE_NAME,
{"last_processed_room": last_processed_room},
)

return processed, False

# If we haven't got a last processed room then just use the empty
# string, which will compare before all room IDs correctly.
last_processed_room = progress.get("last_processed_room", "")

row_count, finished = await self.db_pool.runInteraction(
"_background_current_state_membership_update",
_background_current_state_membership_txn,
last_processed_room,
)

if finished:
await self.db_pool.updates._end_background_update(
_CURRENT_STATE_MEMBERSHIP_UPDATE_NAME
)

return row_count


class RoomMemberStore(
RoomMemberWorkerStore,
Expand Down

0 comments on commit 409ef7b

Please sign in to comment.