Skip to content

Commit

Permalink
perf: avoid getting first page twice
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoCioria committed Jul 20, 2017
1 parent 2728fa5 commit e5dff3f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/getStarHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ async function generateUrls(repo) {

// used to calculate total stars for this page
const pageIndexes = pageNum <= sampleNum ?
range(pageNum) :
range(pageNum).slice(1, pageNum) :
range(sampleNum).map(n => Math.round(n / sampleNum * pageNum) - 1); // for bootstrap bug

// store sampleUrls to be rquested
const sampleUrls = pageIndexes.map(pageIndex => `${initUrl}?page=${pageIndex}`);

console.log("pageIndexes", pageIndexes);
return { sampleUrls, pageIndexes };
return { firstPage: initRes, sampleUrls, pageIndexes };
}

/**
Expand All @@ -58,13 +58,13 @@ async function generateUrls(repo) {
*/
async function getStarHistory(repo) {

const { sampleUrls, pageIndexes } = await generateUrls(repo).catch(e => {
const { sampleUrls, pageIndexes, firstPage } = await generateUrls(repo).catch(e => {
throw e;
});

// promises to request sampleUrls

const getArray = sampleUrls.map(url => axiosGit.get(url));
const getArray = [firstPage].concat(sampleUrls.map(url => axiosGit.get(url)));

const resArray = await Promise.all(getArray)
.catch(res => {
Expand Down

0 comments on commit e5dff3f

Please sign in to comment.