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

Commit 8940d1b

Browse files
authored
Add /notifications endpoint to workers (#16265)
1 parent a83f75a commit 8940d1b

File tree

6 files changed

+42
-37
lines changed

6 files changed

+42
-37
lines changed

changelog.d/16265.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow `/notifications` endpoint to be routed to workers.

docker/configure_workers_and_start.py

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
"^/_matrix/client/(r0|v3|unstable)/password_policy$",
184184
"^/_matrix/client/(api/v1|r0|v3|unstable)/directory/room/.*$",
185185
"^/_matrix/client/(r0|v3|unstable)/capabilities$",
186+
"^/_matrix/client/(r0|v3|unstable)/notifications$",
186187
],
187188
"shared_extra_conf": {},
188189
"worker_extra_conf": "",

docs/workers.md

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ information.
246246
^/_matrix/client/(r0|v3|unstable)/user/.*/filter(/|$)
247247
^/_matrix/client/(api/v1|r0|v3|unstable)/directory/room/.*$
248248
^/_matrix/client/(r0|v3|unstable)/capabilities$
249+
^/_matrix/client/(r0|v3|unstable)/notifications$
249250

250251
# Encryption requests
251252
^/_matrix/client/(r0|v3|unstable)/keys/query$

synapse/rest/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def register_servlets(client_resource: HttpServer, hs: "HomeServer") -> None:
123123
if is_main_process:
124124
report_event.register_servlets(hs, client_resource)
125125
openid.register_servlets(hs, client_resource)
126-
notifications.register_servlets(hs, client_resource)
126+
notifications.register_servlets(hs, client_resource)
127127
devices.register_servlets(hs, client_resource)
128128
if is_main_process:
129129
thirdparty.register_servlets(hs, client_resource)

synapse/rest/client/notifications.py

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
class NotificationsServlet(RestServlet):
3737
PATTERNS = client_patterns("/notifications$")
3838

39+
CATEGORY = "Client API requests"
40+
3941
def __init__(self, hs: "HomeServer"):
4042
super().__init__()
4143
self.store = hs.get_datastores().main

synapse/storage/databases/main/event_push_actions.py

+36-36
Original file line numberDiff line numberDiff line change
@@ -1740,42 +1740,6 @@ def _clear_old_push_actions_staging_txn(txn: LoggingTransaction) -> bool:
17401740
# We sleep to ensure that we don't overwhelm the DB.
17411741
await self._clock.sleep(1.0)
17421742

1743-
1744-
class EventPushActionsStore(EventPushActionsWorkerStore):
1745-
EPA_HIGHLIGHT_INDEX = "epa_highlight_index"
1746-
1747-
def __init__(
1748-
self,
1749-
database: DatabasePool,
1750-
db_conn: LoggingDatabaseConnection,
1751-
hs: "HomeServer",
1752-
):
1753-
super().__init__(database, db_conn, hs)
1754-
1755-
self.db_pool.updates.register_background_index_update(
1756-
self.EPA_HIGHLIGHT_INDEX,
1757-
index_name="event_push_actions_u_highlight",
1758-
table="event_push_actions",
1759-
columns=["user_id", "stream_ordering"],
1760-
)
1761-
1762-
self.db_pool.updates.register_background_index_update(
1763-
"event_push_actions_highlights_index",
1764-
index_name="event_push_actions_highlights_index",
1765-
table="event_push_actions",
1766-
columns=["user_id", "room_id", "topological_ordering", "stream_ordering"],
1767-
where_clause="highlight=1",
1768-
)
1769-
1770-
# Add index to make deleting old push actions faster.
1771-
self.db_pool.updates.register_background_index_update(
1772-
"event_push_actions_stream_highlight_index",
1773-
index_name="event_push_actions_stream_highlight_index",
1774-
table="event_push_actions",
1775-
columns=["highlight", "stream_ordering"],
1776-
where_clause="highlight=0",
1777-
)
1778-
17791743
async def get_push_actions_for_user(
17801744
self,
17811745
user_id: str,
@@ -1834,6 +1798,42 @@ def f(
18341798
]
18351799

18361800

1801+
class EventPushActionsStore(EventPushActionsWorkerStore):
1802+
EPA_HIGHLIGHT_INDEX = "epa_highlight_index"
1803+
1804+
def __init__(
1805+
self,
1806+
database: DatabasePool,
1807+
db_conn: LoggingDatabaseConnection,
1808+
hs: "HomeServer",
1809+
):
1810+
super().__init__(database, db_conn, hs)
1811+
1812+
self.db_pool.updates.register_background_index_update(
1813+
self.EPA_HIGHLIGHT_INDEX,
1814+
index_name="event_push_actions_u_highlight",
1815+
table="event_push_actions",
1816+
columns=["user_id", "stream_ordering"],
1817+
)
1818+
1819+
self.db_pool.updates.register_background_index_update(
1820+
"event_push_actions_highlights_index",
1821+
index_name="event_push_actions_highlights_index",
1822+
table="event_push_actions",
1823+
columns=["user_id", "room_id", "topological_ordering", "stream_ordering"],
1824+
where_clause="highlight=1",
1825+
)
1826+
1827+
# Add index to make deleting old push actions faster.
1828+
self.db_pool.updates.register_background_index_update(
1829+
"event_push_actions_stream_highlight_index",
1830+
index_name="event_push_actions_stream_highlight_index",
1831+
table="event_push_actions",
1832+
columns=["highlight", "stream_ordering"],
1833+
where_clause="highlight=0",
1834+
)
1835+
1836+
18371837
def _action_has_highlight(actions: Collection[Union[Mapping, str]]) -> bool:
18381838
for action in actions:
18391839
if not isinstance(action, dict):

0 commit comments

Comments
 (0)