From 6ff7303321d61ffc795055f8f6ee298263a60752 Mon Sep 17 00:00:00 2001 From: Travis Abendshien Date: Mon, 9 Sep 2024 12:09:59 -0700 Subject: [PATCH] fix: use `birthtime` for default library sorting The cutoff for how many files get sorted also changes to 150,000. --- tagstudio/src/core/library.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tagstudio/src/core/library.py b/tagstudio/src/core/library.py index 3fb2dc90f..3e5af00cc 100644 --- a/tagstudio/src/core/library.py +++ b/tagstudio/src/core/library.py @@ -7,6 +7,7 @@ import datetime import logging import os +import platform import time import traceback import xml.etree.ElementTree as ET @@ -917,12 +918,18 @@ def refresh_dir(self) -> Generator: yield self.dir_file_count start_time = time.time() # Sorts the files by date modified, descending. - if len(self.files_not_in_library) <= 100000: + if len(self.files_not_in_library) <= 150000: try: - self.files_not_in_library = sorted( - self.files_not_in_library, - key=lambda t: -(self.library_dir / t).stat().st_ctime, - ) + if platform.system() == "Windows" or platform.system() == "Darwin": + self.files_not_in_library = sorted( + self.files_not_in_library, + key=lambda t: -(self.library_dir / t).stat().st_birthtime, # type: ignore[attr-defined] + ) + else: + self.files_not_in_library = sorted( + self.files_not_in_library, + key=lambda t: -(self.library_dir / t).stat().st_ctime, + ) except (FileExistsError, FileNotFoundError): print( "[LIBRARY] [ERROR] Couldn't sort files, some were moved during the scanning/sorting process." @@ -930,7 +937,7 @@ def refresh_dir(self) -> Generator: pass else: print( - "[LIBRARY][INFO] Not bothering to sort files because there's OVER 100,000! Better sorting methods will be added in the future." + "[LIBRARY][INFO] Not bothering to sort files because there's OVER 150,000! Better sorting methods will be added in the future." ) def refresh_missing_files(self):