Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate initial SSR and cache for default pages in the PB installation process #693

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import saveElements from "./utils/saveElements";
import savePages from "./utils/savePages";
import path from "path";
import loadJson from "load-json-file";
import got from "got";

export const install = async (
root: any,
args: {[key: string]: any},
context: {[key: string]: any}
) => {
// Start the download of initial Page Builder page / block images.
const { PbSettings, PbCategory, PbMenu } = context.models;
const { PbSettings, PbCategory, PbMenu, PbPage } = context.models;

// 1. Check if Page Builder is already installed.
let settings = await PbSettings.load();
Expand All @@ -38,7 +39,6 @@ export const install = async (
}

if (step === 1) {
// /tmp/installation-files/apiPageBuilder/data/categoriesData.json'","
const INSTALL_EXTRACT_DIR = await downloadInstallationFiles();
const categoriesData: {[key: string]: any}[] = await loadJson(
path.join(INSTALL_EXTRACT_DIR, "data/categoriesData.json")
Expand Down Expand Up @@ -115,6 +115,22 @@ export const install = async (

installation.getStep(5).markAsCompleted();
await settings.save();

// Asynchronously send a GET request to each page so that the SSR cache gets populated.
const initialPages = await PbPage.find();
for (let i = 0; i < initialPages.length; i++) {
const url = await initialPages[i].fullUrl;
try {
await got(url, {
...args,
timeout: 200,
retry: 0
});
} catch {
// Do nothing.
}
}

return new Response(true);
}
} catch (e) {
Expand Down