mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Fix event chain bg update. (#9118)
We passed in a graph to `sorted_topologically` which didn't have an entry for each node (as we dropped nodes with no edges).
This commit is contained in:
parent
d2479c6870
commit
1a08e0cdab
1
changelog.d/9118.misc
Normal file
1
changelog.d/9118.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Improve efficiency of large state resolutions.
|
@ -92,7 +92,7 @@ def sorted_topologically(
|
|||||||
node = heapq.heappop(zero_degree)
|
node = heapq.heappop(zero_degree)
|
||||||
yield node
|
yield node
|
||||||
|
|
||||||
for edge in reverse_graph[node]:
|
for edge in reverse_graph.get(node, []):
|
||||||
if edge in degree_map:
|
if edge in degree_map:
|
||||||
degree_map[edge] -= 1
|
degree_map[edge] -= 1
|
||||||
if degree_map[edge] == 0:
|
if degree_map[edge] == 0:
|
||||||
|
@ -56,6 +56,14 @@ class SortTopologically(TestCase):
|
|||||||
graph = {} # type: Dict[int, List[int]]
|
graph = {} # type: Dict[int, List[int]]
|
||||||
self.assertEqual(list(sorted_topologically([], graph)), [])
|
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):
|
def test_disconnected(self):
|
||||||
"Test that a graph with no edges work"
|
"Test that a graph with no edges work"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user