@@ -1313,6 +1313,13 @@ def _required_state_changes(
1313
1313
prev_wildcard = prev_required_state_map .get (StateValues .WILDCARD , set ())
1314
1314
request_wildcard = request_required_state_map .get (StateValues .WILDCARD , set ())
1315
1315
1316
+ # If we were previously fetching everything ("*", "*"), always update the effective
1317
+ # room required state config to match the request. And since we we're previously
1318
+ # already fetching everything, we don't have to fetch anything now that they've
1319
+ # narrowed.
1320
+ if StateValues .WILDCARD in prev_wildcard :
1321
+ return request_required_state_map , StateFilter .none ()
1322
+
1316
1323
# If a event type wildcard has been added or removed we don't try and do
1317
1324
# anything fancy, and instead always update the effective room required
1318
1325
# state config to match the request.
@@ -1349,6 +1356,11 @@ def _required_state_changes(
1349
1356
# Always update changes to include the newly added keys
1350
1357
changes [event_type ] = request_state_keys
1351
1358
1359
+ if StateValues .WILDCARD in old_state_keys :
1360
+ # We were previously fetching everything for this type, so we don't need to
1361
+ # fetch anything new.
1362
+ continue
1363
+
1352
1364
# Record the new state keys to fetch for this type.
1353
1365
if StateValues .WILDCARD in request_state_keys :
1354
1366
# If we have added a wildcard then we always just fetch everything.
@@ -1358,8 +1370,8 @@ def _required_state_changes(
1358
1370
if state_key == StateValues .ME :
1359
1371
added .append ((event_type , user_id ))
1360
1372
elif state_key == StateValues .LAZY :
1361
- # We handle lazy loading separately, so don't need to
1362
- # explicitly add anything here.
1373
+ # We handle lazy loading separately (outside this function), so
1374
+ # don't need to explicitly add anything here.
1363
1375
pass
1364
1376
else :
1365
1377
added .append ((event_type , state_key ))
@@ -1397,17 +1409,17 @@ def _required_state_changes(
1397
1409
request_state_key_wildcard = StateValues .WILDCARD in request_state_keys
1398
1410
1399
1411
if old_state_key_wildcard != request_state_key_wildcard :
1400
- # If a wildcard has been added or removed we always update the
1401
- # required state when any state with the same type has changed .
1412
+ # If a state_key wildcard has been added or removed, we always update the
1413
+ # effective room required state config to match the request .
1402
1414
changes [event_type ] = request_state_keys
1403
1415
continue
1404
1416
1405
1417
old_state_key_lazy = StateValues .LAZY in old_state_keys
1406
1418
request_state_key_lazy = StateValues .LAZY in request_state_keys
1407
1419
1408
1420
if old_state_key_lazy != request_state_key_lazy :
1409
- # If a "$LAZY" has been added or removed we always update the
1410
- # required state for simplicity .
1421
+ # If a "$LAZY" has been added or removed we always update the effective room
1422
+ # required state config to match the request .
1411
1423
changes [event_type ] = request_state_keys
1412
1424
continue
1413
1425
0 commit comments