dev-mode compile: purge .web dir at last min to reduce downtime window (#1430)

This commit is contained in:
jackie-pc 2023-07-26 16:04:48 -07:00 committed by GitHub
parent d0fc965c7f
commit 7a09554cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@ dist/*
examples/
.idea
.vscode
.coverage
.coverage
venv

View File

@ -3,6 +3,7 @@ repos:
rev: v0.0.244
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.313

View File

@ -467,23 +467,23 @@ class App(Base):
)
task = progress.add_task("Compiling: ", total=len(self.pages))
# TODO: include all work done in progress indicator, not just self.pages
for render, kwargs in DECORATED_ROUTES:
self.add_page(render, **kwargs)
# Get the env mode.
config = get_config()
# Empty the .web pages directory
compiler.purge_web_pages_dir()
# Store the compile results.
compile_results = []
# Compile the pages in parallel.
custom_components = set()
# TODO Anecdotally, processes=2 works 10% faster (cpu_count=12)
thread_pool = ThreadPool()
with progress:
for route, component in self.pages.items():
# TODO: this progress does not reflect actual threaded task completion
progress.advance(task)
component.add_style(self.style)
compile_results.append(
@ -505,6 +505,8 @@ class App(Base):
# Get the results.
compile_results = [result.get() for result in compile_results]
# TODO the compile tasks below may also benefit from parallelization too
# Compile the custom components.
compile_results.append(compiler.compile_components(custom_components))
@ -521,10 +523,12 @@ class App(Base):
)
compile_results.append(compiler.compile_tailwind(config.tailwind))
# Empty the .web pages directory
compiler.purge_web_pages_dir()
# Write the pages at the end to trigger the NextJS hot reload only once.
thread_pool = ThreadPool()
for output_path, code in compile_results:
compiler_utils.write_page(output_path, code)
thread_pool.apply_async(compiler_utils.write_page, args=(output_path, code))
thread_pool.close()
thread_pool.join()

View File

@ -9,7 +9,7 @@ ImportDict = Dict[str, Set[ImportVar]]
def merge_imports(*imports) -> ImportDict:
"""Merge two import dicts together.
"""Merge multiple import dicts together.
Args:
*imports: The list of import dicts to merge.