mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 07:05:43 -03:00
Checkpoint
This commit is contained in:
@@ -62,48 +62,37 @@ class LoraFileHandler(FileSystemEventHandler):
|
||||
|
||||
logger.info(f"Processing {len(changes)} file changes")
|
||||
|
||||
async with self.scanner._cache._lock:
|
||||
# 获取当前缓存
|
||||
cache = await self.scanner.get_cached_data()
|
||||
|
||||
needs_resort = False
|
||||
new_folders = set() # 用于收集新的文件夹
|
||||
|
||||
for action, file_path in changes:
|
||||
try:
|
||||
if action == 'add':
|
||||
# 扫描新文件
|
||||
lora_data = await self.scanner.scan_single_lora(file_path)
|
||||
if lora_data:
|
||||
cache.raw_data.append(lora_data)
|
||||
new_folders.add(lora_data['folder']) # 收集新文件夹
|
||||
needs_resort = True
|
||||
|
||||
elif action == 'remove':
|
||||
# 从缓存中移除
|
||||
cache.raw_data = [
|
||||
item for item in cache.raw_data
|
||||
if item['file_path'] != file_path
|
||||
]
|
||||
cache = await self.scanner.get_cached_data() # 先完成可能的初始化
|
||||
needs_resort = False
|
||||
new_folders = set() # 用于收集新的文件夹
|
||||
|
||||
for action, file_path in changes:
|
||||
try:
|
||||
if action == 'add':
|
||||
# 扫描新文件
|
||||
lora_data = await self.scanner.scan_single_lora(file_path)
|
||||
if lora_data:
|
||||
cache.raw_data.append(lora_data)
|
||||
new_folders.add(lora_data['folder']) # 收集新文件夹
|
||||
needs_resort = True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing {action} for {file_path}: {e}")
|
||||
elif action == 'remove':
|
||||
# 从缓存中移除
|
||||
cache.raw_data = [
|
||||
item for item in cache.raw_data
|
||||
if item['file_path'] != file_path
|
||||
]
|
||||
needs_resort = True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing {action} for {file_path}: {e}")
|
||||
|
||||
if needs_resort:
|
||||
await cache.resort()
|
||||
|
||||
if needs_resort:
|
||||
cache.sorted_by_name = sorted(
|
||||
self.scanner._cache.raw_data,
|
||||
key=lambda x: x['model_name'].lower() # Case-insensitive sort
|
||||
)
|
||||
cache.sorted_by_date = sorted(
|
||||
self.scanner._cache.raw_data,
|
||||
key=itemgetter('modified'),
|
||||
reverse=True
|
||||
)
|
||||
|
||||
# 更新文件夹列表,包括新添加的文件夹
|
||||
all_folders = set(cache.folders) | new_folders
|
||||
cache.folders = sorted(list(all_folders))
|
||||
# 更新文件夹列表,包括新添加的文件夹
|
||||
all_folders = set(cache.folders) | new_folders
|
||||
cache.folders = sorted(list(all_folders))
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in process_changes: {e}")
|
||||
|
||||
Reference in New Issue
Block a user