summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2022-04-22 13:32:00 +0100
committerRichard van der Hoff <richard@matrix.org>2022-04-22 13:32:00 +0100
commitb81cab0794ba2be20e8e8e8eb13aff76b3968fd5 (patch)
tree64a9f48069c1e00584b58cd0404a4796cd13a466
parentRename a couple of variables (diff)
downloadsynapse-b81cab0794ba2be20e8e8e8eb13aff76b3968fd5.tar.xz
skip a dict construction
we may as well just chain together the two inputs
-rw-r--r--synapse/handlers/federation.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py

index 0c70addcd3..8b995c0d3e 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py
@@ -1,4 +1,4 @@ -# Copyright 2014-2021 The Matrix.org Foundation C.I.C. +# Copyright 2014-2022 The Matrix.org Foundation C.I.C. # Copyright 2020 Sorunome # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,6 +15,7 @@ """Contains handlers for federation events.""" +import itertools import logging from http import HTTPStatus from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Tuple, Union @@ -230,16 +231,18 @@ class FederationHandler: if not filtered_extremities and not insertion_events_to_be_backfilled: return False - extremities = { - **oldest_events_with_depth, - # TODO: insertion_events_to_be_backfilled is currently skipping the filtered_extremities checks - **insertion_events_to_be_backfilled, - } + # TODO: insertion_events_to_be_backfilled is currently skipping the filtered_extremities checks - # Check if we reached a point where we should start backfilling. + # we now have a list of potential places to backpaginate from. We prefer to + # start with the most recent (ie, max depth), so let's sort the list. sorted_extremeties_tuples: List[Tuple[str, int]] = sorted( - extremities.items(), key=lambda e: -int(e[1]) + itertools.chain( + oldest_events_with_depth.items(), + insertion_events_to_be_backfilled.items(), + ), + key=lambda e: -int(e[1]), ) + max_depth = sorted_extremeties_tuples[0][1] # If we're approaching an extremity we trigger a backfill, otherwise we