diff --git a/public/js/friendsGraph.js b/public/js/friendsGraph.js index 07bf5e4..28f97c0 100644 --- a/public/js/friendsGraph.js +++ b/public/js/friendsGraph.js @@ -82,7 +82,7 @@ function addFriends(username, apiPath, page) } } - if(data.length === 30) + if(page < 50 && data.length === 30) { addFriends(username, apiPath, page+ 1).then(function() { @@ -161,7 +161,7 @@ function processConnections(user, apiPoint, page) { addConnection(user, data[i]) } - if(data.length === 30) + if(page < 50 && data.length === 30) { processConnections(user, apiPoint, page + 1).then(function() { diff --git a/routes/api.js b/routes/api.js index b5d36a0..0c0befb 100644 --- a/routes/api.js +++ b/routes/api.js @@ -42,12 +42,13 @@ function queryGitHubAPI(requestURL) cache.put(requestURL, response.body); }).catch(error => { - reject(error); - cache.put(requestURL, response.body); + resolve(error); + cache.put(requestURL, error); }); } else { + console.log("Fetched From Cahce"); resolve(apiData); } }) @@ -68,12 +69,21 @@ routes.get('/*', (request, result) => result.end(); }).catch(function(error) { - if(error.hasOwnProperty("id") || error[0].hasOwnProperty("id")) + try { - result.write(JSON.stringify(error)); + if(error.hasOwnProperty("id") || error[0].hasOwnProperty("id")) + { + result.write(JSON.stringify(error)); + } } + catch(error) {}; result.end(); - }) + }); + + if(cache.size() > 500000) + { + cache.clear(); + } }); module.exports = routes; \ No newline at end of file