Skip to content

Commit

Permalink
Improve performance by using same browser variable on broken-links
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Alfaro committed Oct 16, 2018
1 parent f9f7dc3 commit 66a3cfe
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions broken-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ async function asyncForEach(array, callback) {
}
}

async function getImages(url , index=0){
async function getImages(url , index=0, browser){
let username = process.env.HT_USER;
let password = process.env.HT_PASS;
let browser = await puppeteer.launch();
let page = await browser.newPage();
// let old_url = process.env.OLD_DOMAIN.replace(/\/$/, '') + '/' +url;
let new_url = process.env.NEW_DOMAIN.replace(/\/$/, '') + '/' +url;
Expand All @@ -34,7 +33,7 @@ async function getImages(url , index=0){
console.log('Saved!');
});
}
await browser.close();
// await browser.close();
}
catch (e){
console.error(e);
Expand All @@ -52,7 +51,9 @@ async function getImages(url , index=0){

await asyncForEach(same_site_links, async (link, index) => {
try {
await getImages(link, index);
let browser = await puppeteer.launch();
await getImages(link, index, browser);
await browser.close();
}
catch (e){
console.error(e);
Expand Down

0 comments on commit 66a3cfe

Please sign in to comment.