Skip to content

Commit 3596179

Browse files
authored
feat(scully): add support to set the number of cores during rendering, (#420)
* feat(scully): add support to set the number of cores during rendering * fix(lib): export startmonitoring, made the wrong method private * docs(scully): start of plugin docs
1 parent 61f8f7f commit 3596179

5 files changed

Lines changed: 40 additions & 5 deletions

File tree

docs/scully-provided-plugins.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Scully system plugins
3+
order: 700
4+
---
5+
6+
# This document descrobes the plugins that are build into scully.
7+
8+
## json (router)
9+
10+
## ignored (router)
11+
12+
## contentFolder (router+render)
13+
14+
## seoHrefOptimise (render)
15+
16+
Adds an trailing slash (`/`) to all routes that are in the routeService. Increases SEO scoring
17+
18+
## adoc (fileHandler)
19+
20+
## md (fileHandler)
21+
22+
## default
23+
24+
The default routing plugin. Does add the route verbatim.

projects/scullyio/ng-lib/src/lib/transfer-state/transfer-state.service.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {DOCUMENT} from '@angular/common';
22
import {Inject, Injectable} from '@angular/core';
33
import {NavigationEnd, NavigationStart, Router} from '@angular/router';
4-
import {BehaviorSubject, NEVER, Observable, of, from} from 'rxjs';
4+
import {BehaviorSubject, NEVER, Observable, of} from 'rxjs';
55
import {
66
catchError,
77
filter,
@@ -167,7 +167,7 @@ export class TransferStateService {
167167
/**
168168
* starts monitoring the router, and keep the url from the last completed navigation handy.
169169
*/
170-
setupStartNavMonitoring() {
170+
private setupStartNavMonitoring() {
171171
if (!isScullyGenerated()) {
172172
return;
173173
}
@@ -176,7 +176,14 @@ export class TransferStateService {
176176
this.nextUrl.subscribe();
177177
}
178178

179-
async fetchTransferState(): Promise<void> {
179+
useScullyTransferState<T>(name: string, originalState: Observable<T>): Observable<T> {
180+
if (isScullyGenerated()) {
181+
return this.getState(name);
182+
}
183+
return originalState.pipe(tap(state => this.setState(name, state)));
184+
}
185+
186+
private async fetchTransferState(): Promise<void> {
180187
/** helper to read the part before the first slash (ignores leading slash) */
181188
const base = (url: string) => url.split('/').filter(part => part.trim() !== '')[0];
182189
/** put this in the next event cycle so the correct route can be read */

scully/utils/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {logError, logWarn, yellow} from './log';
77
import {validateConfig} from './validateConfig';
88
import {compileConfig} from './compileConfig';
99
import {readAngularJson} from './read-anguar-json';
10+
import {cpus} from 'os';
1011
export const angularRoot = findAngularJsonPath();
1112
export const scullyConfig: ScullyConfig = {} as ScullyConfig;
1213

@@ -46,6 +47,7 @@ const loadIt = async () => {
4647
projectRoot: projectConfig.root,
4748
distFolder,
4849
inlineStateOnly: false,
50+
maxRenderThreads: cpus().length,
4951
appPort: /** 1864 */ 'herodevs'.split('').reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
5052
staticport: /** 1668 */ 'scully'.split('').reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
5153
reloadPort: /** 2667 */ 'scullyLiveReload'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import {cpus} from 'os';
21
import {performance} from 'perf_hooks';
32
import {routeContentRenderer} from '../../renderPlugins/routeContentRenderer';
43
import {writeToFs} from '../../systemPlugins/writeToFs.plugin';
54
import {asyncPool} from '../asyncPool';
5+
import {scullyConfig} from '../config';
66
import {performanceIds} from '../performanceIds';
77

88
export async function renderParallel(dataRoutes) {
99
const renderRoute = route =>
1010
routeContentRenderer(route).then((html: string) => writeToFs(route.route, html));
1111
performance.mark('startRender');
1212
performanceIds.add('Render');
13-
const renderPool = await asyncPool(cpus().length, dataRoutes, renderRoute);
13+
const renderPool = await asyncPool(scullyConfig.maxRenderThreads, dataRoutes, renderRoute);
1414
performance.mark('stopRender');
1515
return renderPool;
1616
}

scully/utils/interfacesandenums.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export interface ScullyConfig {
4343
hostUrl?: string;
4444
/** optional guessParserOptions, if this is provided we are going to pass those options to the guess parser. */
4545
guessParserOptions?: GuessParserOptions;
46+
/** the maximum of concurrent puppeteer tabs open. defaults to the available amounts of cores */
47+
maxRenderThreads: number;
4648
}
4749

4850
interface RouteConfig {

0 commit comments

Comments
 (0)