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

Track notification counts per thread (implement MSC3773) (redo) #13776

Merged
merged 26 commits into from
Oct 4, 2022
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9cb167c
Update filtering to include the thread notifications flag.
clokep Sep 8, 2022
8ac2f32
Ensure that the thread_id column is non-null and then require it to b…
clokep Sep 9, 2022
111fe57
Add infrastructure to pass notifications per thread.
clokep Sep 8, 2022
62aa85b
Calculate thread specific notification counts.
clokep Sep 8, 2022
cb679e2
Clarify comment.
clokep Sep 16, 2022
ba00c5f
Simplify handling of summaries with neither notifications or unread c…
clokep Sep 16, 2022
eb56567
Delete old push summaries.
clokep Sep 16, 2022
e6f97ec
Merge remote-tracking branch 'origin/develop' into clokep/threads-not…
clokep Sep 16, 2022
4f4711a
Merge remote-tracking branch 'origin/develop' into clokep/threads-not…
clokep Sep 19, 2022
8b63c5b
Fix postgres compatibility.
clokep Sep 19, 2022
c3783df
Merge remote-tracking branch 'origin/develop' into clokep/threads-not…
clokep Sep 20, 2022
c4f2d50
Create a constant for "main".
clokep Sep 20, 2022
6927e59
Reduce duplicated code.
clokep Sep 20, 2022
1d05975
Lint
clokep Sep 20, 2022
28b5a1f
Merge remote-tracking branch 'origin/develop' into clokep/threads-not…
clokep Sep 22, 2022
55d15a3
Threads must already be summarized between the stream orderings that …
clokep Sep 22, 2022
56c21e4
Don't delete empty push summaries.
clokep Sep 22, 2022
241b40c
Merge remote-tracking branch 'origin/develop' into clokep/threads-not…
clokep Sep 23, 2022
a04258f
Merge remote-tracking branch 'origin/develop' into clokep/threads-not…
clokep Sep 26, 2022
ddbb644
Merge remote-tracking branch 'origin/develop' into clokep/threads-not…
clokep Sep 27, 2022
79452e9
Merge remote-tracking branch 'origin/develop' into clokep/threads-not…
clokep Sep 28, 2022
b0d9008
Merge remote-tracking branch 'origin/develop' into clokep/threads-not…
clokep Sep 28, 2022
f279a15
Merge remote-tracking branch 'origin/develop' into clokep/threads-not…
clokep Sep 29, 2022
f416be9
Merge branch 'develop' into clokep/threads-notif-2
clokep Oct 4, 2022
0b1b432
Update for changes in develop.
clokep Oct 4, 2022
bd6c80c
Update background index numbers.
clokep Oct 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Delete old push summaries.
  • Loading branch information
clokep committed Sep 16, 2022
commit eb56567ebee9206f44b1d4c5b1b6bd4ce9a4ced9
64 changes: 60 additions & 4 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,14 @@ def _rotate_notifs_before_txn(
)

async def _remove_old_push_actions_that_have_rotated(self) -> None:
"""Clear out old push actions that have been summarised."""
"""
Performs two clean-ups:

1. Clear out old push actions that have been summarised (and are older
than 1 day ago).
2. Clear out old push summaries that are empty (and are older than 30
days ago).
"""

# We want to clear out anything that is older than a day that *has* already
# been rotated.
Expand All @@ -1343,7 +1350,7 @@ async def _remove_old_push_actions_that_have_rotated(self) -> None:
retcol="stream_ordering",
)

max_stream_ordering_to_delete = min(
max_action_stream_ordering_to_delete = min(
rotated_upto_stream_ordering, self.stream_ordering_day_ago
)

Expand All @@ -1361,7 +1368,7 @@ def remove_old_push_actions_that_have_rotated_txn(
ORDER BY stream_ordering ASC LIMIT 1 OFFSET ?
""",
(
max_stream_ordering_to_delete,
max_action_stream_ordering_to_delete,
batch_size,
),
)
Expand All @@ -1370,7 +1377,7 @@ def remove_old_push_actions_that_have_rotated_txn(
if stream_row:
(stream_ordering,) = stream_row
else:
stream_ordering = max_stream_ordering_to_delete
stream_ordering = max_action_stream_ordering_to_delete

# We need to use a inclusive bound here to handle the case where a
# single stream ordering has more than `batch_size` rows.
Expand All @@ -1386,6 +1393,47 @@ def remove_old_push_actions_that_have_rotated_txn(

return txn.rowcount < batch_size

max_summary_stream_ordering_to_delete = self.stream_ordering_month_ago

def remove_old_read_push_summaries_txn(txn: LoggingTransaction) -> bool:
# We don't want to clear out too much at a time, so we bound our
# deletes.
batch_size = self._rotate_count

txn.execute(
"""
SELECT stream_ordering FROM event_push_summary
WHERE stream_ordering <= ? AND notif_count = 0 AND COALESCE(unread_count, 0) = 0
ORDER BY stream_ordering ASC LIMIT 1 OFFSET ?
""",
(
max_summary_stream_ordering_to_delete,
batch_size,
),
)
stream_row = txn.fetchone()

if stream_row:
(stream_ordering,) = stream_row
else:
stream_ordering = max_summary_stream_ordering_to_delete

# We need to use a inclusive bound here to handle the case where a
# single stream ordering has more than `batch_size` rows.
txn.execute(
"""
DELETE FROM event_push_summary
WHERE stream_ordering <= ? AND notif_count = 0 AND COALESCE(unread_count, 0) = 0
""",
(stream_ordering,),
)

logger.info(
"Rotating notifications, deleted %s push summaries", txn.rowcount
)

return txn.rowcount < batch_size

while True:
done = await self.db_pool.runInteraction(
"_remove_old_push_actions_that_have_rotated",
Expand All @@ -1394,6 +1442,14 @@ def remove_old_push_actions_that_have_rotated_txn(
if done:
break

while True:
done = await self.db_pool.runInteraction(
"_remove_old_read_push_summaries_txn",
remove_old_read_push_summaries_txn,
)
if done:
break


class EventPushActionsStore(EventPushActionsWorkerStore):
EPA_HIGHLIGHT_INDEX = "epa_highlight_index"
Expand Down