Cache doctrees between reading and writing phases

This commit is contained in:
Adam Turner 2023-01-04 05:57:03 +00:00
parent a9b0f2708b
commit 463a69664c
2 changed files with 11 additions and 1 deletions

View File

@ -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],

View File

@ -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)