Compare commits

..
Author SHA1 Message Date
Manolo Edge 3e9b0a0fc5 Add cache to function response (#22)
* Add cache to function response

* Lowered cache-control maxage to 5 min

* Changed cache control directives to public, max-age

* Added cache-control to pin.js
2020-07-15 12:11:43 +05:30
anuraghazra fe1ce9d693 feat: limit year fetching 2020-07-10 14:59:53 +05:30
anuraghazra 6cee3e67ed fix: total commits count 2020-07-10 14:38:35 +05:30
Anurag Hazra 6b04481c81 Merge pull request #12 from anuraghazra/fix-layout
fix: fixed overflowing layout
2020-07-10 12:45:11 +05:30
2 changed files with 56 additions and 2 deletions
+55 -2
View File
@@ -17,7 +17,7 @@ async function fetchStats(username) {
totalCount
}
contributionsCollection {
totalCommitContributions
contributionYears
}
pullRequests(first: 100) {
totalCount
@@ -53,9 +53,61 @@ async function fetchStats(username) {
const user = res.data.data.user;
// FETCH ALL COMMITS
let commitPromises = user.contributionsCollection.contributionYears.map(
async (year) => {
// Don't fetch contributions older than 2008 (Perf optimization)
if (year < 2008) {
return {
user: { contributionsCollection: { totalCommitContributions: 0 } },
};
}
const currentDate = new Date();
currentDate.setFullYear(year, 0, 0);
const res = await axios({
url: "https://api.github.com/graphql",
method: "post",
headers: {
Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
},
data: {
query: `
query userInfo($login: String!, $from: DateTime!) {
user(login: $login) {
contributionsCollection(from: $from) {
totalCommitContributions
}
}
}
`,
variables: {
login: username,
from: currentDate.toISOString(),
},
},
});
console.log(
currentDate.toDateString(),
res.data.data.user.contributionsCollection.totalCommitContributions
);
return res.data.data;
}
);
const allCommits = await Promise.all(commitPromises);
const totalCommits = allCommits.reduce((preYear, currYear) => {
return (
preYear + currYear.user.contributionsCollection.totalCommitContributions
);
}, 0);
stats.name = user.name;
stats.totalIssues = user.issues.totalCount;
stats.totalCommits = user.contributionsCollection.totalCommitContributions;
stats.totalCommits = totalCommits;
stats.totalPRs = user.pullRequests.totalCount;
stats.contributedTo = user.repositoriesContributedTo.totalCount;
@@ -137,6 +189,7 @@ module.exports = async (req, res) => {
const stats = await fetchStats(username);
res.setHeader('Cache-Control', 'public, max-age=300');
res.setHeader("Content-Type", "image/svg+xml");
res.send(
renderSVG(stats, {
+1
View File
@@ -120,6 +120,7 @@ module.exports = async (req, res) => {
const repoData = await fetchRepo(username, repo);
res.setHeader('Cache-Control', 'public, max-age=300');
res.setHeader("Content-Type", "image/svg+xml");
res.send(renderRepoCard(repoData));
};