-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomerslow-priorityperformace
Description
Cache destination path computation in FileConfig
Problem
FileConfig computes the destination path (filename + subdirectory) multiple times:
- Once for
download_idgeneration - Once for actual download operation
- Potentially multiple times during progress tracking/logging
Each computation calls get_destination_filename() which may involve URL parsing and sanitisation.
Proposed Solution
Add destination_relative_path as a @computed_field property that caches the relative path:
@computed_field
@property
def destination_relative_path(self) -> Path:
"""Relative path from base directory to where file will be saved.
Cached computed field combining filename and optional subdirectory.
This is the path component that uniquely identifies where the file
will be saved, relative to the base download directory.
Returns:
Relative path (Path object)
Examples:
>>> config = FileConfig(url="https://example.com/file.txt")
>>> config.destination_relative_path
PosixPath('example.com-file.txt')
>>> config = FileConfig(
... url="https://example.com/file.txt",
... destination_subdir="docs"
... )
>>> config.destination_relative_path
PosixPath('docs/example.com-file.txt')
"""
filename = self.get_destination_filename()
if self.destination_subdir:
return Path(self.destination_subdir) / filename
return Path(filename)
def get_destination_path(self, base_dir: Path) -> Path:
"""Get full absolute destination path.
Combines base_dir with cached relative path.
Args:
base_dir: Base download directory
Returns:
Full absolute path where file should be saved
"""
return base_dir / self.destination_relative_path
@computed_field
@property
def download_id(self) -> str:
# update implementation to use self.destination_relative_pathBenefits
- Performance: Path computed once, cached for reuse
- Consistency:
download_idandget_destination_path()use same cached value
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomerslow-priorityperformace