22
22
from http import HTTPStatus
23
23
from typing import (
24
24
TYPE_CHECKING ,
25
+ Collection ,
25
26
Dict ,
26
27
Iterable ,
27
28
List ,
@@ -1364,11 +1365,12 @@ async def get_event(event_id: str):
1364
1365
1365
1366
event_infos .append (_NewEventInfo (event , None , auth ))
1366
1367
1367
- await self ._auth_and_persist_events (
1368
- destination ,
1369
- room_id ,
1370
- event_infos ,
1371
- )
1368
+ if event_infos :
1369
+ await self ._auth_and_persist_events (
1370
+ destination ,
1371
+ room_id ,
1372
+ event_infos ,
1373
+ )
1372
1374
1373
1375
def _sanity_check_event (self , ev : EventBase ) -> None :
1374
1376
"""
@@ -2077,7 +2079,7 @@ async def _auth_and_persist_events(
2077
2079
self ,
2078
2080
origin : str ,
2079
2081
room_id : str ,
2080
- event_infos : Iterable [_NewEventInfo ],
2082
+ event_infos : Collection [_NewEventInfo ],
2081
2083
backfilled : bool = False ,
2082
2084
) -> None :
2083
2085
"""Creates the appropriate contexts and persists events. The events
@@ -2088,6 +2090,9 @@ async def _auth_and_persist_events(
2088
2090
Notifies about the events where appropriate.
2089
2091
"""
2090
2092
2093
+ if not event_infos :
2094
+ return
2095
+
2091
2096
async def prep (ev_info : _NewEventInfo ):
2092
2097
event = ev_info .event
2093
2098
with nested_logging_context (suffix = event .event_id ):
@@ -2216,13 +2221,14 @@ async def _persist_auth_tree(
2216
2221
raise
2217
2222
events_to_context [e .event_id ].rejected = RejectedReason .AUTH_ERROR
2218
2223
2219
- await self .persist_events_and_notify (
2220
- room_id ,
2221
- [
2222
- (e , events_to_context [e .event_id ])
2223
- for e in itertools .chain (auth_events , state )
2224
- ],
2225
- )
2224
+ if auth_events or state :
2225
+ await self .persist_events_and_notify (
2226
+ room_id ,
2227
+ [
2228
+ (e , events_to_context [e .event_id ])
2229
+ for e in itertools .chain (auth_events , state )
2230
+ ],
2231
+ )
2226
2232
2227
2233
new_event_context = await self .state_handler .compute_event_context (
2228
2234
event , old_state = state
@@ -3061,7 +3067,13 @@ async def persist_events_and_notify(
3061
3067
the same room.
3062
3068
backfilled: Whether these events are a result of
3063
3069
backfilling or not
3070
+
3071
+ Returns:
3072
+ The stream ID after which all events have been persisted.
3064
3073
"""
3074
+ if not event_and_contexts :
3075
+ return self .store .get_current_events_token ()
3076
+
3065
3077
instance = self .config .worker .events_shard_config .get_instance (room_id )
3066
3078
if instance != self ._instance_name :
3067
3079
# Limit the number of events sent over replication. We choose 200
0 commit comments