Skip to content

Commit

Permalink
coalesce some list updates (talonhub#1348)
Browse files Browse the repository at this point in the history
Snippets and file manager list updates trigger more context refreshes
than necessary. Due to an indentation issue, snippets are currently
triggering 101 full context re-evaluations every time snippets
load/reload (linear to number of snippets).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jeff Knaus <knaus.jeff@gmail.com>
  • Loading branch information
3 people authored and MartinRykfors committed Aug 14, 2024
1 parent 7c345f1 commit d266531
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 7 additions & 3 deletions core/snippets/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ def update_snippets():
insertions_phrase_map.update(insertions_phrase)
wrapper_map.update(wrappers)

ctx.lists["user.snippet"] = insertion_map
ctx.lists["user.snippet_with_phrase"] = insertions_phrase_map
ctx.lists["user.snippet_wrapper"] = wrapper_map
ctx.lists.update(
{
"user.snippet": insertion_map,
"user.snippet_with_phrase": insertions_phrase_map,
"user.snippet_wrapper": wrapper_map,
}
)


def get_snippets() -> list[Snippet]:
Expand Down
16 changes: 12 additions & 4 deletions tags/file_manager/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,12 @@ def clear_lists():
or len(ctx.lists["self.file_manager_files"]) > 0
):
current_folder_page = current_file_page = 1
ctx.lists["self.file_manager_directories"] = []
ctx.lists["self.file_manager_files"] = []
ctx.lists.update(
{
"self.file_manager_directories": [],
"self.file_manager_files": [],
}
)
folder_selections = []
file_selections = []

Expand Down Expand Up @@ -371,8 +375,12 @@ def update_lists(path=None):
files = {}

current_folder_page = current_file_page = 1
ctx.lists["self.file_manager_directories"] = directories
ctx.lists["self.file_manager_files"] = files
ctx.lists.update(
{
"self.file_manager_directories": directories,
"self.file_manager_files": files,
}
)

folder_selections = list(set(directories.values()))
folder_selections.sort(key=str.casefold)
Expand Down

0 comments on commit d266531

Please sign in to comment.