chore: Improve logging by adding SHA256 hash calculation timing and clarifying metadata creation messages.

This commit is contained in:
Will Miao
2026-01-03 08:56:34 +08:00
parent 07aeeb6c70
commit f13f22c949
2 changed files with 7 additions and 1 deletions

View File

@@ -949,7 +949,7 @@ class ModelScanner:
metadata = self.model_class.from_civitai_info(version_info, file_info, file_path) metadata = self.model_class.from_civitai_info(version_info, file_info, file_path)
metadata.preview_url = find_preview_file(file_name, os.path.dirname(file_path)) metadata.preview_url = find_preview_file(file_name, os.path.dirname(file_path))
await MetadataManager.save_metadata(file_path, metadata) await MetadataManager.save_metadata(file_path, metadata)
logger.debug(f"Created metadata from .civitai.info for {file_path}") logger.info(f"Created metadata from .civitai.info for {file_path} (Reason: .civitai.info was found but .metadata.json was missing)")
except Exception as e: except Exception as e:
logger.error(f"Error creating metadata from .civitai.info for {file_path}: {e}") logger.error(f"Error creating metadata from .civitai.info for {file_path}: {e}")
else: else:

View File

@@ -2,6 +2,7 @@ from datetime import datetime
import os import os
import json import json
import logging import logging
import time
from typing import Any, Dict, Optional, Type, Union from typing import Any, Dict, Optional, Type, Union
from .models import BaseModelMetadata, LoraMetadata from .models import BaseModelMetadata, LoraMetadata
@@ -203,7 +204,11 @@ class MetadataManager:
preview_url = find_preview_file(base_name, dir_path) preview_url = find_preview_file(base_name, dir_path)
# Calculate file hash # Calculate file hash
start_hash_time = time.perf_counter()
logger.debug(f"Calculating SHA256 hash for {real_path}...")
sha256 = await calculate_sha256(real_path) sha256 = await calculate_sha256(real_path)
hash_duration = time.perf_counter() - start_hash_time
logger.info(f"SHA256 hash calculated for {real_path} in {hash_duration:.3f}s")
# Create instance based on model type # Create instance based on model type
if model_class.__name__ == "CheckpointMetadata": if model_class.__name__ == "CheckpointMetadata":
@@ -255,6 +260,7 @@ class MetadataManager:
# await MetadataManager._enrich_metadata(metadata, real_path) # await MetadataManager._enrich_metadata(metadata, real_path)
# Save the created metadata # Save the created metadata
logger.info(f"Creating new .metadata.json for {file_path} (Reason: No existing metadata found)")
await MetadataManager.save_metadata(file_path, metadata) await MetadataManager.save_metadata(file_path, metadata)
return metadata return metadata