Skip to content

Commit 8444b8d

Browse files
Remove bug causing exponential lag due to persistent parameters in tag_sort.py
1 parent b9316fa commit 8444b8d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tagstudio/src/core/tag_sort.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TagSortDirection(Flag):
3434
def normalize_sort(old_sort: Sort = None) -> Sort:
3535
if old_sort is None:
3636
old_sort = []
37-
old_sort.extend(_default_sort)
37+
old_sort.extend(_default_sort.copy())
3838

3939
sorted_properties: set[TagSortProperty] = set()
4040
new_sort = []
@@ -72,8 +72,11 @@ def reverse_sort(old_sort: Sort) -> Sort:
7272

7373

7474
def get_key(
75-
lib: Library, tag_id_list, sort: Sort = _default_sort
75+
lib: Library, tag_id_list, sort: Sort = None
7676
) -> Callable[[int], list[Any]]:
77+
if sort is None:
78+
sort = _default_sort.copy()
79+
7780
sort = normalize_sort(sort)
7881

7982
outer_sort: Sort = []
@@ -177,9 +180,12 @@ def _get_canonical_lineage(
177180
inner_sort: Sort,
178181
tag_id: int,
179182
tag_id_list: list[int],
180-
last_generation_ids=set([-1]),
183+
last_generation_ids=None,
181184
first_gen=True,
182185
) -> list[list[Any]]:
186+
if first_gen:
187+
last_generation_ids = set([-1])
188+
183189
ancestor_id_queue: list[int] = [tag_id]
184190
encountered_tag_ids: set[int] = set(last_generation_ids)
185191
encountered_tag_ids.add(tag_id)

0 commit comments

Comments
 (0)