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

Commit 37eaf9c

Browse files
authored
Fix-up assertions about last stream token in push (#9020)
The last stream token is always known and we do not need to handle none.
1 parent 31b1905 commit 37eaf9c

File tree

5 files changed

+8
-14
lines changed

5 files changed

+8
-14
lines changed

changelog.d/9020.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add type hints to push module.

synapse/push/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class PusherConfig:
4040
ts = attr.ib(type=int)
4141
lang = attr.ib(type=Optional[str])
4242
data = attr.ib(type=Optional[JsonDict])
43-
last_stream_ordering = attr.ib(type=Optional[int])
43+
last_stream_ordering = attr.ib(type=int)
4444
last_success = attr.ib(type=Optional[int])
4545
failing_since = attr.ib(type=Optional[int])
4646

synapse/push/emailpusher.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ async def _unsafe_process(self) -> None:
157157
being run.
158158
"""
159159
start = 0 if INCLUDE_ALL_UNREAD_NOTIFS else self.last_stream_ordering
160-
assert start is not None
161160
unprocessed = await self.store.get_unread_push_actions_for_user_in_range_for_email(
162161
self.user_id, start, self.max_stream_ordering
163162
)
@@ -220,12 +219,8 @@ async def _unsafe_process(self) -> None:
220219
)
221220

222221
async def save_last_stream_ordering_and_success(
223-
self, last_stream_ordering: Optional[int]
222+
self, last_stream_ordering: int
224223
) -> None:
225-
if last_stream_ordering is None:
226-
# This happens if we haven't yet processed anything
227-
return
228-
229224
self.last_stream_ordering = last_stream_ordering
230225
pusher_still_exists = await self.store.update_pusher_last_stream_ordering_and_success(
231226
self.app_id,

synapse/push/httppusher.py

-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ async def _unsafe_process(self) -> None:
176176
Never call this directly: use _process which will only allow this to
177177
run once per pusher.
178178
"""
179-
assert self.last_stream_ordering is not None
180179
unprocessed = await self.store.get_unread_push_actions_for_user_in_range_for_http(
181180
self.user_id, self.last_stream_ordering, self.max_stream_ordering
182181
)
@@ -205,7 +204,6 @@ async def _unsafe_process(self) -> None:
205204
http_push_processed_counter.inc()
206205
self.backoff_delay = HttpPusher.INITIAL_BACKOFF_SEC
207206
self.last_stream_ordering = push_action["stream_ordering"]
208-
assert self.last_stream_ordering is not None
209207
pusher_still_exists = await self.store.update_pusher_last_stream_ordering_and_success(
210208
self.app_id,
211209
self.pushkey,

synapse/push/pusherpool.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ async def add_pusher(
106106

107107
time_now_msec = self.clock.time_msec()
108108

109+
# create the pusher setting last_stream_ordering to the current maximum
110+
# stream ordering, so it will process pushes from this point onwards.
111+
last_stream_ordering = self.store.get_room_max_stream_ordering()
112+
109113
# we try to create the pusher just to validate the config: it
110114
# will then get pulled out of the database,
111115
# recreated, added and started: this means we have only one
@@ -124,16 +128,12 @@ async def add_pusher(
124128
ts=time_now_msec,
125129
lang=lang,
126130
data=data,
127-
last_stream_ordering=None,
131+
last_stream_ordering=last_stream_ordering,
128132
last_success=None,
129133
failing_since=None,
130134
)
131135
)
132136

133-
# create the pusher setting last_stream_ordering to the current maximum
134-
# stream ordering, so it will process pushes from this point onwards.
135-
last_stream_ordering = self.store.get_room_max_stream_ordering()
136-
137137
await self.store.add_pusher(
138138
user_id=user_id,
139139
access_token=access_token,

0 commit comments

Comments
 (0)