Skip to content

Commit

Permalink
Cache the result of _file_checksum()
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Oct 19, 2024
1 parent 3c6ccd3 commit 10f6b6b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sphinx/builders/html/_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import warnings
import zlib
from functools import cache
from typing import TYPE_CHECKING, Any, NoReturn

from sphinx.deprecation import RemovedInSphinx90Warning
Expand Down Expand Up @@ -172,9 +173,14 @@ def _file_checksum(outdir: Path, filename: str | os.PathLike[str]) -> str:
if '?' in filename:
msg = f'Local asset file paths must not contain query strings: {filename!r}'
raise ThemeError(msg)
return _file_checksum_inner(outdir.joinpath(filename).resolve())


@cache
def _file_checksum_inner(file: Path) -> str:
try:
# Remove all carriage returns to avoid checksum differences
content = outdir.joinpath(filename).read_bytes().translate(None, b'\r')
content = file.read_bytes().translate(None, b'\r')
except FileNotFoundError:
return ''
if not content:
Expand Down

0 comments on commit 10f6b6b

Please sign in to comment.