mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-27 12:30:13 +03:00
refactor: Remove MD5 calculation from node files listing
Remove MD5 checksum calculation from the node files API since disk image files are dynamic and change frequently. MD5 calculation was also causing significant performance overhead. Changes: - Remove md5sum field from NodeFile schema - Remove MD5 calculation from list_node_files method - Improve error handling for timestamp conversion - Simplify code by removing lambda functions Performance improvement: - Response time reduced from ~0.5-1s to ~0.017s (30-60x faster) - Especially beneficial for large files and multiple files Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
fae7b2eabe
commit
e6df144ae8
@ -440,42 +440,43 @@ class Project:
|
||||
|
||||
files = []
|
||||
try:
|
||||
for filename in os.listdir(node_full_path):
|
||||
file_path = os.path.join(node_full_path, filename)
|
||||
if os.path.isfile(file_path) and not filename.endswith(".ghost"):
|
||||
try:
|
||||
# Get file stat information
|
||||
stat_info = await wait_run_in_executor(os.stat, file_path)
|
||||
|
||||
# Get file extension
|
||||
_, extension = os.path.splitext(filename)
|
||||
extension = extension.lstrip('.')
|
||||
|
||||
# Format timestamps as ISO 8601
|
||||
created_at = await wait_run_in_executor(
|
||||
lambda: datetime.datetime.fromtimestamp(stat_info.st_ctime).isoformat()
|
||||
)
|
||||
modified_at = await wait_run_in_executor(
|
||||
lambda: datetime.datetime.fromtimestamp(stat_info.st_mtime).isoformat()
|
||||
)
|
||||
|
||||
# Get MD5 checksum
|
||||
md5sum = await wait_run_in_executor(self._hash_file, file_path)
|
||||
|
||||
file_info = {
|
||||
"path": filename,
|
||||
"md5sum": md5sum,
|
||||
"size": stat_info.st_size,
|
||||
"created_at": created_at,
|
||||
"modified_at": modified_at,
|
||||
"extension": extension
|
||||
}
|
||||
files.append(file_info)
|
||||
except OSError as e:
|
||||
log.warning(f"Error getting metadata for file '{filename}': {e}")
|
||||
continue
|
||||
filenames = os.listdir(node_full_path)
|
||||
except OSError as e:
|
||||
log.error(f"Error listing node files: {e}")
|
||||
log.error(f"Error listing node directory: {e}")
|
||||
return files
|
||||
|
||||
for filename in filenames:
|
||||
file_path = os.path.join(node_full_path, filename)
|
||||
if not os.path.isfile(file_path) or filename.endswith(".ghost"):
|
||||
continue
|
||||
|
||||
try:
|
||||
# Get file stat information
|
||||
stat_info = await wait_run_in_executor(os.stat, file_path)
|
||||
|
||||
# Get file extension
|
||||
_, extension = os.path.splitext(filename)
|
||||
extension = extension.lstrip('.')
|
||||
|
||||
# Format timestamps as ISO 8601
|
||||
try:
|
||||
created_at = datetime.datetime.fromtimestamp(stat_info.st_ctime).isoformat()
|
||||
modified_at = datetime.datetime.fromtimestamp(stat_info.st_mtime).isoformat()
|
||||
except (OSError, OverflowError, ValueError) as e:
|
||||
log.warning(f"Invalid timestamp for '{filename}': {e}")
|
||||
created_at = modified_at = ""
|
||||
|
||||
file_info = {
|
||||
"path": filename,
|
||||
"size": stat_info.st_size,
|
||||
"created_at": created_at,
|
||||
"modified_at": modified_at,
|
||||
"extension": extension
|
||||
}
|
||||
files.append(file_info)
|
||||
except OSError as e:
|
||||
log.warning(f"Error getting metadata for file '{filename}': {e}")
|
||||
continue
|
||||
|
||||
return files
|
||||
|
||||
|
||||
@ -111,7 +111,6 @@ class NodeFile(BaseModel):
|
||||
"""
|
||||
|
||||
path: str = Field(..., description="File name")
|
||||
md5sum: str = Field(..., description="File checksum")
|
||||
size: int = Field(..., description="File size in bytes")
|
||||
created_at: str = Field(..., description="File creation time (ISO 8601)")
|
||||
modified_at: str = Field(..., description="File modification time (ISO 8601)")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user