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

Commit 3693ea6

Browse files
Fix iteration in _remove_deleted_email_pushers background job. (#10734)
1 parent 78e590d commit 3693ea6

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

changelog.d/10734.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove pushers when deleting a 3pid from an account. Pushers for old unlinked emails will also be deleted.

synapse/storage/databases/main/pusher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,11 @@ def _delete_pushers(txn) -> int:
430430
"""
431431

432432
txn.execute(sql, (last_pusher, batch_size))
433+
rows = txn.fetchall()
433434

434435
last = None
435436
num_deleted = 0
436-
for row in txn:
437+
for row in rows:
437438
last = row[0]
438439
num_deleted += 1
439440
self.db_pool.simple_delete_txn(

tests/push/test_email.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,50 @@ def test_no_email_sent_after_removed(self):
344344
pushers = list(pushers)
345345
self.assertEqual(len(pushers), 0)
346346

347+
def test_remove_unlinked_pushers_background_job(self):
348+
"""Checks that all existing pushers associated with unlinked email addresses are removed
349+
upon running the remove_deleted_email_pushers background update.
350+
"""
351+
# disassociate the user's email address manually (without deleting the pusher).
352+
# This resembles the old behaviour, which the background update below is intended
353+
# to clean up.
354+
self.get_success(
355+
self.hs.get_datastore().user_delete_threepid(
356+
self.user_id, "email", "[email protected]"
357+
)
358+
)
359+
360+
# Run the "remove_deleted_email_pushers" background job
361+
self.get_success(
362+
self.hs.get_datastore().db_pool.simple_insert(
363+
table="background_updates",
364+
values={
365+
"update_name": "remove_deleted_email_pushers",
366+
"progress_json": "{}",
367+
"depends_on": None,
368+
},
369+
)
370+
)
371+
372+
# ... and tell the DataStore that it hasn't finished all updates yet
373+
self.hs.get_datastore().db_pool.updates._all_done = False
374+
375+
# Now let's actually drive the updates to completion
376+
while not self.get_success(
377+
self.hs.get_datastore().db_pool.updates.has_completed_background_updates()
378+
):
379+
self.get_success(
380+
self.hs.get_datastore().db_pool.updates.do_next_background_update(100),
381+
by=0.1,
382+
)
383+
384+
# Check that all pushers with unlinked addresses were deleted
385+
pushers = self.get_success(
386+
self.hs.get_datastore().get_pushers_by({"user_name": self.user_id})
387+
)
388+
pushers = list(pushers)
389+
self.assertEqual(len(pushers), 0)
390+
347391
def _check_for_mail(self):
348392
"""Check that the user receives an email notification"""
349393

0 commit comments

Comments
 (0)