From d5084b3bfb6fc0515214ede7f4dd2fa15c546f3d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 14 Jan 2021 17:55:57 +0000 Subject: [PATCH 1/2] Fix event chain bg update. We passed in a graph to `sorted_topologically` which didn't have an entry for each node (as we dropped nodes with no edges). --- synapse/util/iterutils.py | 2 +- tests/util/test_itertools.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/synapse/util/iterutils.py b/synapse/util/iterutils.py index f7b4857a8464..6ef2b008a4d1 100644 --- a/synapse/util/iterutils.py +++ b/synapse/util/iterutils.py @@ -92,7 +92,7 @@ def sorted_topologically( node = heapq.heappop(zero_degree) yield node - for edge in reverse_graph[node]: + for edge in reverse_graph.get(node, []): if edge in degree_map: degree_map[edge] -= 1 if degree_map[edge] == 0: diff --git a/tests/util/test_itertools.py b/tests/util/test_itertools.py index 1184cea5a33f..522c8061f973 100644 --- a/tests/util/test_itertools.py +++ b/tests/util/test_itertools.py @@ -56,6 +56,14 @@ def test_empty(self): graph = {} # type: Dict[int, List[int]] self.assertEqual(list(sorted_topologically([], graph)), []) + def test_handle_empty_graph(self): + "Test that a graph where a node doesn't have an entry is treated as empty" + + graph = {} # type: Dict[int, List[int]] + + # For disconnected nodes the output is simply sorted. + self.assertEqual(list(sorted_topologically([1, 2], graph)), [1, 2]) + def test_disconnected(self): "Test that a graph with no edges work" From 225a523cf4ca44475f5bb7fccb3d2faf2a2dd865 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 14 Jan 2021 17:58:21 +0000 Subject: [PATCH 2/2] Newsfile --- changelog.d/9118.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/9118.misc diff --git a/changelog.d/9118.misc b/changelog.d/9118.misc new file mode 100644 index 000000000000..346741d982f4 --- /dev/null +++ b/changelog.d/9118.misc @@ -0,0 +1 @@ +Improve efficiency of large state resolutions.