Skip to content

Commit

Permalink
Cache the value of documentation_pages
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed May 2, 2023
1 parent 0b567ef commit c22eedd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mkdocs/structure/files.py
Expand Up @@ -38,6 +38,7 @@ class Files:
def __init__(self, files: List[File]) -> None:
self._files = files
self._src_uris: Optional[Dict[str, File]] = None
self._documentation_pages: Optional[Sequence[File]] = None

def __iter__(self) -> Iterator[File]:
"""Iterate over the files within."""
Expand Down Expand Up @@ -70,12 +71,12 @@ def get_file_from_path(self, path: str) -> Optional[File]:

def append(self, file: File) -> None:
"""Append file to Files collection."""
self._src_uris = None
self._src_uris = self._documentation_pages = None
self._files.append(file)

def remove(self, file: File) -> None:
"""Remove file from Files collection."""
self._src_uris = None
self._src_uris = self._documentation_pages = None
self._files.remove(file)

def copy_static_files(self, dirty: bool = False) -> None:
Expand All @@ -86,7 +87,9 @@ def copy_static_files(self, dirty: bool = False) -> None:

def documentation_pages(self) -> Sequence[File]:
"""Return iterable of all Markdown page file objects."""
return [file for file in self if file.is_documentation_page()]
if self._documentation_pages is None:
self._documentation_pages = [file for file in self if file.is_documentation_page()]
return self._documentation_pages

def static_pages(self) -> Sequence[File]:
"""Return iterable of all static page file objects."""
Expand Down

0 comments on commit c22eedd

Please sign in to comment.