Misc Bug Fixes

- Catches additional exception in the sorting process of new files added to the library
- Skips this sorting process if there are more than 100,000 files (this is a temporary sorting measure, anyway)
- Possibly improved performance during the functionless (and cursed) "Applying Configured Macros" step of loading new files
This commit is contained in:
Travis Abendshien
2024-04-30 02:41:07 -07:00
parent 9b90bfad84
commit a10478bc8b
2 changed files with 20 additions and 12 deletions

View File

@@ -962,12 +962,15 @@ class Library:
# print('')
# Sorts the files by date modified, descending.
try:
self.files_not_in_library = sorted(
self.files_not_in_library, key=lambda t: -os.stat(os.path.normpath(self.library_dir + '/' + t)).st_ctime)
except FileExistsError:
print(f'[LIBRARY] [ERROR] Couldn\'t sort files, some were moved during the scanning/sorting process.')
pass
if len(self.files_not_in_library) <= 100000:
try:
self.files_not_in_library = sorted(
self.files_not_in_library, key=lambda t: -os.stat(os.path.normpath(self.library_dir + '/' + t)).st_ctime)
except (FileExistsError, FileNotFoundError):
print(f'[LIBRARY][ERROR] Couldn\'t sort files, some were moved during the scanning/sorting process.')
pass
else:
print(f'[LIBRARY][INFO] Not bothering to sort files because there\'s OVER 100,000! Better sorting methods will be added in the future.')
def refresh_missing_files(self):
"""Tracks the number of Entries that point to an invalid file path."""

View File

@@ -515,6 +515,8 @@ class QtDriver(QObject):
iterator.value.connect(lambda x: pw.update_progress(x+1))
iterator.value.connect(lambda x: pw.update_label(f'Scanning Directories for New Files...\n{x+1} File{"s" if x+1 != 1 else ""} Searched, {len(self.lib.files_not_in_library)} New Files Found'))
r = CustomRunnable(lambda:iterator.run())
# r.done.connect(lambda: (pw.hide(), pw.deleteLater(), self.filter_items('')))
# vvv This one runs the macros when adding new files to the library.
r.done.connect(lambda: (pw.hide(), pw.deleteLater(), self.add_new_files_runnable()))
QThreadPool.globalInstance().start(r)
@@ -568,12 +570,15 @@ class QtDriver(QObject):
def new_file_macros_runnable(self, new_ids):
"""Threaded method that runs macros on a set of Entry IDs."""
# sleep(1)
logging.info(f'ANFR: {QThread.currentThread()}')
for i, id in enumerate(new_ids):
# pb.setValue(i)
# pb.setLabelText(f'Running Configured Macros on {i}/{len(new_ids)} New Entries')
# self.run_macro('autofill', id)
yield i
# logging.info(f'ANFR: {QThread.currentThread()}')
# for i, id in enumerate(new_ids):
# # pb.setValue(i)
# # pb.setLabelText(f'Running Configured Macros on {i}/{len(new_ids)} New Entries')
# # self.run_macro('autofill', id)
# NOTE: I don't know. I don't know why it needs this. The whole program
# falls apart if this method doesn't run, and it DOESN'T DO ANYTHING
yield 0
# self.main_window.statusbar.showMessage('', 3)