Browse Source

Improved caching and performance for organization members api calls.

performance-improvements
jrtechs 4 years ago
parent
commit
2688316b5e
3 changed files with 69 additions and 20 deletions
  1. +7
    -18
      public/js/createOrgRepoGraph.js
  2. +7
    -2
      public/js/githubAPI.js
  3. +55
    -0
      routes/api.js

+ 7
- 18
public/js/createOrgRepoGraph.js View File

@ -6,31 +6,19 @@
* @param page * @param page
* @returns {Promise<any>} * @returns {Promise<any>}
*/ */
function addOrgUsers(orgname, page)
function addOrgUsers(orgname)
{ {
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject)
{ {
queryAPIByOrg(API_ORG_MEMBERS + "?page=" + page, orgname, function(data)
getOrganizationMembers(orgname, (data)=>
{ {
for(var i = 0;i < data.length; i++) for(var i = 0;i < data.length; i++)
{ {
addPersonToGraph(data[i]); addPersonToGraph(data[i]);
} }
if(data.length === 30)
{
addOrgUsers(orgname, page + 1).then(function()
{
resolve();
});
}
else
{
total = 2*(data.length + (page * 30));
resolve();
}
}, function(error)
total = data.length;
resolve();
}, (error)=>
{ {
console.log(error); console.log(error);
resolve(); resolve();
@ -38,6 +26,7 @@ function addOrgUsers(orgname, page)
}) })
} }
/** /**
* Creates a graph * Creates a graph
* @param username * @param username
@ -51,7 +40,7 @@ function createOrgRepoGraph(orgname, containerName, graphsTitle)
nodes = []; nodes = [];
edges = []; edges = [];
addOrgUsers(orgname, 1).then(function()
addOrgUsers(orgname).then(function()
{ {
createConnections().then( () => { createConnections().then( () => {
var container = document.getElementById(containerName); var container = document.getElementById(containerName);

+ 7
- 2
public/js/githubAPI.js View File

@ -79,8 +79,13 @@ function getOrganizationRepositories(orgName, suc, err)
{ {
//ex: http://localhost:7000/api/org/repositories/ComputerScienceHouse //ex: http://localhost:7000/api/org/repositories/ComputerScienceHouse
const urlpath = APIROOT + "/org/repositories/" + orgName; const urlpath = APIROOT + "/org/repositories/" + orgName;
console.log("what is even happening rn.");
console.log(urlpath);
runAjax(urlpath, suc, err);
}
function getOrganizationMembers(orgName, suc, err)
{
const urlpath = APIROOT + "/org/users/" + orgName;
runAjax(urlpath, suc, err); runAjax(urlpath, suc, err);
} }

+ 55
- 0
routes/api.js View File

@ -222,6 +222,41 @@ function queryFriends(user)
} }
/**
*
* Fetches all of the members of an organization from the
* API or cache
*
* /orgs/RITlug/members?page=1
*
* @param {*} orgName
*/
function getOrganizationMembers(orgName)
{
const cacheHit = cache.get("/org/users/" + orgName);
return new Promise((resolve, reject)=>
{
if(cacheHit == null)
{
fetchAllWithPagination(API_ORGS_PATH + orgName + "/members", 1, []).then((mems)=>
{
var minimized = minimizeFriends(mems);
resolve(minimized);
cache.put("/org/users/" + orgName, minimized);
}).catch((err)=>
{
console.log(err)
})
}
else
{
console.log("Org members cache hit");
resolve(cacheHit);
}
});
}
/** /**
* Minimizes the JSON for a list of repositories * Minimizes the JSON for a list of repositories
* *
@ -275,6 +310,9 @@ function queryRepositories(user, orgsOrUsers)
} }
/**
* /users/name/following/followers
*/
routes.get("/friends/:name", (request, result)=> routes.get("/friends/:name", (request, result)=>
{ {
queryFriends(request.params.name).then(friends=> queryFriends(request.params.name).then(friends=>
@ -290,6 +328,23 @@ routes.get("/friends/:name", (request, result)=>
}); });
routes.get("/org/users/:name", (request, result)=>
{
getOrganizationMembers(request.params.name).then(friends=>
{
result.json(friends)
.end();
}).catch(error=>
{
result.status(500)
.json({error: 'API error fetching friends'})
.end();
});
});
routes.get("/repositories/:name", (request, result)=> routes.get("/repositories/:name", (request, result)=>
{ {
queryRepositories(request.params.name, API_USER_PATH).then(repos=> queryRepositories(request.params.name, API_USER_PATH).then(repos=>

Loading…
Cancel
Save