From c9e5884d4c80516b637fbae9d2fb450450ce7203 Mon Sep 17 00:00:00 2001 From: Roland Date: Fri, 16 Dec 2022 09:31:11 -0700 Subject: [PATCH] Removing unnecessary get_mimetype. --- wrolpi/files/lib.py | 2 +- wrolpi/files/models.py | 6 +++--- wrolpi/files/test/test_lib.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wrolpi/files/lib.py b/wrolpi/files/lib.py index e78a3916..46c6ff6b 100644 --- a/wrolpi/files/lib.py +++ b/wrolpi/files/lib.py @@ -184,7 +184,7 @@ async def _refresh_files_list(paths: List[pathlib.Path], idempotency: datetime.d # Add any new files into the database. new_files = [] if new_paths := (chunk - existing_paths): - new_files = [File(path=i, idempotency=idempotency, mimetype=get_mimetype(i)) for i in new_paths] + new_files = [File(path=i, idempotency=idempotency) for i in new_paths] session.add_all(new_files) # Apply models to all files. Many files will have no model. all_files = existing_files + new_files diff --git a/wrolpi/files/models.py b/wrolpi/files/models.py index 92a14915..809a6680 100644 --- a/wrolpi/files/models.py +++ b/wrolpi/files/models.py @@ -93,7 +93,8 @@ class File(ModelHelper, Base): def do_index(self, force_index: bool = False): """Gather any missing information about this file. Index the contents of this file using an Indexer.""" - self.do_stats() + if not self.mimetype: + self.do_stats() try: if force_index or self.indexed is not True: @@ -120,8 +121,7 @@ class File(ModelHelper, Base): Returns True if the file has changed since last index. Change is detected by comparing old size, mimetype modification datetime.""" - from wrolpi.files.lib import split_path_stem_and_suffix, split_file_name_words - from wrolpi.files.lib import get_mimetype + from wrolpi.files.lib import split_path_stem_and_suffix, split_file_name_words, get_mimetype old_mimetype = self.mimetype old_size = self.size diff --git a/wrolpi/files/test/test_lib.py b/wrolpi/files/test/test_lib.py index ed172c5b..77be95aa 100644 --- a/wrolpi/files/test/test_lib.py +++ b/wrolpi/files/test/test_lib.py @@ -199,7 +199,7 @@ async def test_refresh_a_text_no_indexer(test_session, make_files_structure): @pytest.mark.asyncio async def test_refresh_many_files(test_session, make_files_structure): """Used to profile file refreshing""" - count = 1_000 + count = 10_000 make_files_structure([f'{uuid4()}.txt' for _ in range(count)]) with timer('first refresh'): await lib.refresh_files()