perf: remove repeated project and log filesystem work without weakening checks
This commit is contained in:
1 parent
bbf9bffe32
commit
e6ec267a26
10 files changed
+210
-6
No files matched your search
@@ -110,11 +110,13 @@ def _prepare_project_access(root: Path):
|
||||
if not command.is_file():
|
||||
return
|
||||
rows = []
|
||||
seen = set()
|
||||
with command.open(encoding='utf-8-sig', newline='') as stream:
|
||||
for row in csv.DictReader(stream, delimiter='\t'):
|
||||
value = row.get('project_path')
|
||||
if not value:
|
||||
if not value or value in seen:
|
||||
continue
|
||||
seen.add(value)
|
||||
project = Path(value).resolve(strict=False)
|
||||
if (_fits(project.parent) and len(str(project)) < 260) or not project.is_file():
|
||||
continue
|
||||
|
||||
@@ -226,7 +226,8 @@ def _task_directory(context: LoggingContext, task_id: str) -> Path:
|
||||
if not task_id or Path(task_id).name != task_id or task_id in {".", ".."}:
|
||||
raise TaskCenterError("task_id", "task event requires a safe task identifier")
|
||||
path = context.root / "tasks" / task_id
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
if not path.is_dir():
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
return path
|
||||
|
||||
|
||||
|
||||
@@ -1080,7 +1080,8 @@ def _read_status(status_path: Path) -> tuple[tuple[str, str], ...]:
|
||||
|
||||
|
||||
def _append_log(log_path: Path, entry: str, *, check_rotation: bool = True) -> None:
|
||||
log_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not log_path.parent.is_dir():
|
||||
log_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if check_rotation:
|
||||
rotate_text_log(log_path)
|
||||
with log_path.open("a", encoding="utf-8", newline="\n") as handle:
|
||||
|
||||
@@ -35,7 +35,15 @@ def rotate_text_log(
|
||||
path = Path(path)
|
||||
if max_bytes < 1 or backup_count < 1:
|
||||
raise ValueError("log retention limits must be positive")
|
||||
if not path.exists() or path.stat().st_size <= max_bytes:
|
||||
try:
|
||||
size = path.stat().st_size
|
||||
except (OSError, ValueError):
|
||||
# Preserve pathlib's platform-specific absence/error handling. Only
|
||||
# exceptional paths need the second query; normal logs use one stat.
|
||||
if not path.exists():
|
||||
return False
|
||||
raise
|
||||
if size <= max_bytes:
|
||||
return False
|
||||
if _is_link(path):
|
||||
raise OSError(f"refusing to rotate linked log: {path}")
|
||||
|
||||
Reference in new issue
Block a user