Improve performance wen loading file previews.

This commit is contained in:
Dan Helfman
2026-05-31 18:55:56 -07:00
parent 9748a0298a
commit 30ca942f76
3 changed files with 6 additions and 12 deletions
+3 -8
View File
@@ -75,19 +75,14 @@ class File_preview(textual.widgets.RichLog):
)
def on_file_preview_loaded(self, file_contents):
import time
logger.debug(('on_file_preview_loaded', time.time()))
self.loading_timer.stop()
self.clear()
if file_contents is None:
self.write('Cannot display a preview for this file')
else:
logger.debug(('before write', time.time()))
# Only pass the file path and not its contents to guess_lexer(). Passing the contents is
# more accurate, but also much slower.
self.write(
rich.syntax.Syntax(
file_contents, rich.syntax.Syntax.guess_lexer(self.file_path, file_contents)
)
rich.syntax.Syntax(file_contents, rich.syntax.Syntax.guess_lexer(self.file_path))
)
logger.debug(('after write', time.time()))
-3
View File
@@ -171,9 +171,6 @@ def load_file_preview(
repository dict, an archive name, the path of a file in that archive, and a loading indicator
timer, load the contents of the file and write it into the given file preview widget.
'''
import time
logger.debug(('before get_archive_file_content', time.time()))
file_contents = borgmatic.actions.browse.archive.get_archive_file_content(
config, repository, archive_name, file_path
)
@@ -122,7 +122,9 @@ def test_add_archive_paths_retains_loading_indicator_at_bottom():
def test_directory_list_with_root_directory_adds_loading_indicator():
flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator').once()
flexmock(module.borgmatic.actions.browse.loading).should_receive(
'add_inline_loading_indicator'
).once()
directory_list = module.Directory_list(
config=flexmock(), repository=flexmock(), archive_name='archive'