Skip to content

Commit

Permalink
wp-now: download wordpress and sqlite in parallel (#417)
Browse files Browse the repository at this point in the history
Optimize WordPress and SQLite downloads to be in parallel, It's also an optimization for the tests.
  • Loading branch information
sejas authored May 24, 2023
1 parent bfe268a commit 043f677
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 12 additions & 10 deletions packages/wp-now/src/tests/wp-now.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ import getWpNowTmpPath from '../get-wp-now-tmp-path';

const exampleDir = __dirname + '/mode-examples';

async function downloadWithTimer(name, fn) {
console.log(`Downloading ${name}...`);
console.time(name);
await fn();
console.log(`${name} downloaded.`);
console.timeEnd(name);
}

// Options
test('getWpNowConfig with default options', async () => {
const rawOptions: CliOptions = {
Expand Down Expand Up @@ -176,16 +184,10 @@ describe('Test starting different modes', () => {
*/
beforeAll(async () => {
fs.rmSync(getWpNowTmpPath(), { recursive: true, force: true });
console.log('Downloading WordPress...');
console.time('wordpress');
await downloadWordPress();
console.log('WordPress downloaded.');
console.timeEnd('wordpress');
console.log('Downloading SQLite...');
console.time('sqlite');
await downloadSqliteIntegrationPlugin();
console.log('SQLite downloaded.');
console.timeEnd('sqlite');
await Promise.all([
downloadWithTimer('wordpresss', downloadWordPress),
downloadWithTimer('sqlite', downloadSqliteIntegrationPlugin),
]);
});

/**
Expand Down
8 changes: 5 additions & 3 deletions packages/wp-now/src/wp-now.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ export default async function startWPNow(
});
return { php, phpInstances, options };
}
await downloadWordPress(options.wordPressVersion);
await downloadSqliteIntegrationPlugin();
await downloadMuPlugins();
await Promise.all([
downloadWordPress(options.wordPressVersion),
downloadSqliteIntegrationPlugin(),
downloadMuPlugins(),
]);
const isFirstTimeProject = !fs.existsSync(options.wpContentPath);
await applyToInstances(phpInstances, async (_php) => {
switch (options.mode) {
Expand Down

0 comments on commit 043f677

Please sign in to comment.