Browse Source

Memory improvements to the project.

pull/11/head
Jeffery Russell 5 years ago
parent
commit
dc23245529
2 changed files with 17 additions and 7 deletions
  1. +2
    -2
      public/js/friendsGraph.js
  2. +15
    -5
      routes/api.js

+ 2
- 2
public/js/friendsGraph.js View File

@ -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() addFriends(username, apiPath, page+ 1).then(function()
{ {
@ -161,7 +161,7 @@ function processConnections(user, apiPoint, page)
{ {
addConnection(user, data[i]) addConnection(user, data[i])
} }
if(data.length === 30)
if(page < 50 && data.length === 30)
{ {
processConnections(user, apiPoint, page + 1).then(function() processConnections(user, apiPoint, page + 1).then(function()
{ {

+ 15
- 5
routes/api.js View File

@ -42,12 +42,13 @@ function queryGitHubAPI(requestURL)
cache.put(requestURL, response.body); cache.put(requestURL, response.body);
}).catch(error => }).catch(error =>
{ {
reject(error);
cache.put(requestURL, response.body);
resolve(error);
cache.put(requestURL, error);
}); });
} }
else else
{ {
console.log("Fetched From Cahce");
resolve(apiData); resolve(apiData);
} }
}) })
@ -68,12 +69,21 @@ routes.get('/*', (request, result) =>
result.end(); result.end();
}).catch(function(error) }).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(); result.end();
})
});
if(cache.size() > 500000)
{
cache.clear();
}
}); });
module.exports = routes; module.exports = routes;

Loading…
Cancel
Save