mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2024-09-20 15:26:02 +08:00
Make remove_orphaned even faster
This is not an addiction I swear
This commit is contained in:
parent
be742694d1
commit
2fd5701922
|
@ -28,31 +28,24 @@ class RemoveOrphaned:
|
|||
self.stats = 0
|
||||
logger.separator("Checking for Orphaned Files", space=False, border=False)
|
||||
torrent_files = []
|
||||
root_files = []
|
||||
orphaned_files = []
|
||||
excluded_orphan_files = []
|
||||
|
||||
root_files = util.get_root_files(self.remote_dir, self.root_dir, self.orphaned_dir)
|
||||
root_files = self.executor.submit(util.get_root_files, self.remote_dir, self.root_dir, self.orphaned_dir)
|
||||
|
||||
# Get an updated list of torrents
|
||||
logger.print_line("Locating orphan files", self.config.loglevel)
|
||||
torrent_list = self.qbt.get_torrents({"sort": "added_on"})
|
||||
torrent_files_and_save_path = []
|
||||
for torrent in torrent_list:
|
||||
torrent_files = []
|
||||
for torrent_files_dict in torrent.files:
|
||||
torrent_files.append(torrent_files_dict.name)
|
||||
torrent_files_and_save_path.append((torrent_files, torrent.save_path))
|
||||
|
||||
torrent_files.extend(
|
||||
[
|
||||
fullpath
|
||||
for fullpathlist in self.executor.map(get_full_path_of_torrent_files, torrent_files_and_save_path)
|
||||
for fullpathlist in self.executor.map(self.get_full_path_of_torrent_files, torrent_list)
|
||||
for fullpath in fullpathlist
|
||||
if fullpath not in torrent_files
|
||||
]
|
||||
)
|
||||
|
||||
orphaned_files = set(root_files) - set(torrent_files)
|
||||
orphaned_files = set(root_files.result()) - set(torrent_files)
|
||||
|
||||
if self.config.orphaned["exclude_patterns"]:
|
||||
logger.print_line("Processing orphan exclude patterns")
|
||||
|
@ -93,6 +86,7 @@ class RemoveOrphaned:
|
|||
orphaned_parent_path = set(self.executor.map(self.move_orphan, orphaned_files))
|
||||
logger.print_line("Removing newly empty directories", self.config.loglevel)
|
||||
self.executor.map(lambda dir: util.remove_empty_directories(dir, "**/*"), orphaned_parent_path)
|
||||
|
||||
else:
|
||||
logger.print_line("No Orphaned Files found.", self.config.loglevel)
|
||||
|
||||
|
@ -102,13 +96,14 @@ class RemoveOrphaned:
|
|||
util.move_files(src, dest, True)
|
||||
return os.path.dirname(file).replace(self.root_dir, self.remote_dir)
|
||||
|
||||
def get_full_path_of_torrent_files(self, torrent):
|
||||
torrent_files = map(lambda dict: dict.name, torrent.files)
|
||||
save_path = torrent.save_path
|
||||
|
||||
def get_full_path_of_torrent_files(torrent_files_and_save_path):
|
||||
torrent_files, save_path = torrent_files_and_save_path
|
||||
fullpath_torrent_files = []
|
||||
for file in torrent_files:
|
||||
fullpath = os.path.join(save_path, file)
|
||||
# Replace fullpath with \\ if qbm is running in docker (linux) but qbt is on windows
|
||||
fullpath = fullpath.replace(r"/", "\\") if ":\\" in fullpath else fullpath
|
||||
fullpath_torrent_files.append(fullpath)
|
||||
return fullpath_torrent_files
|
||||
fullpath_torrent_files = []
|
||||
for file in torrent_files:
|
||||
fullpath = os.path.join(save_path, file)
|
||||
# Replace fullpath with \\ if qbm is running in docker (linux) but qbt is on windows
|
||||
fullpath = fullpath.replace(r"/", "\\") if ":\\" in fullpath else fullpath
|
||||
fullpath_torrent_files.append(fullpath)
|
||||
return fullpath_torrent_files
|
||||
|
|
Loading…
Reference in a new issue