Refactor model file processing in ModelScanner to determine root paths and enhance error logging for missing roots.

This commit is contained in:
Will Miao
2025-06-11 15:53:35 +08:00
parent 14238b8d62
commit 06d5bd259c

View File

@@ -669,7 +669,15 @@ class ModelScanner:
batch = new_files[i:i+batch_size] batch = new_files[i:i+batch_size]
for path in batch: for path in batch:
try: try:
model_data = await self.scan_single_model(path) # Find the appropriate root path for this file
root_path = None
for potential_root in self.get_model_roots():
if path.startswith(potential_root):
root_path = potential_root
break
if root_path:
model_data = await self._process_model_file(path, root_path)
if model_data: if model_data:
# Add to cache # Add to cache
self._cache.raw_data.append(model_data) self._cache.raw_data.append(model_data)
@@ -684,12 +692,11 @@ class ModelScanner:
self._tags_count[tag] = self._tags_count.get(tag, 0) + 1 self._tags_count[tag] = self._tags_count.get(tag, 0) + 1
total_added += 1 total_added += 1
else:
logger.error(f"Could not determine root path for {path}")
except Exception as e: except Exception as e:
logger.error(f"Error adding {path} to cache: {e}") logger.error(f"Error adding {path} to cache: {e}")
# Yield control after each batch
await asyncio.sleep(0)
# Find missing files (in cache but not in filesystem) # Find missing files (in cache but not in filesystem)
missing_files = cached_paths - found_paths missing_files = cached_paths - found_paths
total_removed = 0 total_removed = 0