diff options
author | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-01-04 05:57:03 +0000 |
---|---|---|
committer | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-01-04 14:39:40 +0000 |
commit | 463a69664c2b7f51562eb9d15597987e6e6784cd (patch) | |
tree | 1c9e2aa03cbaa51697b5bc3a522b22a190dd6fa5 | |
parent | a9b0f2708b67a355c5f4969ccbbe9bd695518805 (diff) | |
download | sphinx-git-463a69664c2b7f51562eb9d15597987e6e6784cd.tar.gz |
Cache doctrees between reading and writing phases
-rw-r--r-- | sphinx/builders/__init__.py | 2 | ||||
-rw-r--r-- | sphinx/environment/__init__.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index d4e06dff6..20ebfd7d9 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -542,6 +542,8 @@ class Builder: with open(doctree_filename, 'wb') as f: pickle.dump(doctree, f, pickle.HIGHEST_PROTOCOL) + self.env._write_doc_doctree_cache[docname] = doctree + def write( self, build_docnames: Iterable[str], diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index 1f279ceb1..b25643cd0 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -181,6 +181,9 @@ class BuildEnvironment: # docname -> pickled doctree self._pickled_doctree_cache: dict[str, bytes] = {} + # docname -> doctree + self._write_doc_doctree_cache: dict[str, nodes.document] = {} + # File metadata # docname -> dict of metadata items self.metadata: dict[str, dict[str, Any]] = defaultdict(dict) @@ -608,7 +611,12 @@ class BuildEnvironment: toctrees and return it. """ if doctree is None: - doctree = self.get_doctree(docname) + try: + doctree = self._write_doc_doctree_cache.pop(docname) + doctree.settings.env = self + doctree.reporter = LoggingReporter(self.doc2path(docname)) + except KeyError: + doctree = self.get_doctree(docname) # resolve all pending cross-references self.apply_post_transforms(doctree, docname) |