Browse Source

Created new route for fetching all user repositories and minimizes/cahces the json results (closes #26)

performance-improvements
jrtechs 5 years ago
parent
commit
031a234770
3 changed files with 76 additions and 3 deletions
  1. +8
    -0
      public/js/githubAPI.js
  2. +1
    -2
      public/js/profileTimeLine.js
  3. +67
    -1
      routes/api.js

+ 8
- 0
public/js/githubAPI.js View File

@ -67,6 +67,14 @@ function getFriendsAPI(userName, suc, err)
}
function getUserRepositories(userName, suc, err)
{
//ex: http://localhost:7000/api/repositories/jwflory
const urlpath = APIROOT + "/repositories/" + userName;
runAjax(urlpath, suc, err);
}
/**
* Queries github API end points with the backend
* proxy server for github graphs.

+ 1
- 2
public/js/profileTimeLine.js View File

@ -15,7 +15,7 @@ function addRepositories(userName, groupID)
{
return new Promise(function(resolve, reject)
{
queryAPIByUser(API_REPOSITORIES, userName,
getUserRepositories(userName,
function(data)
{
repositoryData = data;
@ -76,7 +76,6 @@ function createProfileTimeLine(username, containerName)
{
var container = document.getElementById(containerName);
var prom = [addRepositories(username, 1)];
var groups = new vis.DataSet([

+ 67
- 1
routes/api.js View File

@ -190,10 +190,12 @@ function queryFriends(user)
}).catch((err)=>
{
console.log(err);
reject("API ERROR");
})
}).catch((error)=>
{
console.log(error);
resolve("API Error");
})
}
else
@ -217,7 +219,71 @@ routes.get("/friends/:name", (request, result)=>
.json({error: 'API error fetching friends'})
.end();
});
})
});
function copyWithProperties(props, obj)
{
var newO = new Object();
for(var i =0; i < props.length; i++)
{
newO[props[i]] = obj[props[i]];
}
return newO;
}
function minimizeRepositories(repositories)
{
var rList = [];
for(var i = 0; i < repositories.length; i++)
{
rList.push(copyWithProperties(["name", "created_at", "homepage",
"description", "language", "forks", "watchers",
"open_issues_count", "license"],
repositories[i]));
}
return rList;
}
const REPOS_PATH = "/repos";
function queryRepositories(user)
{
const cacheHit = cache.get(user + REPOS_PATH);
return new Promise((resolve, reject)=>
{
if(cacheHit == null)
{
fetchAllUsers(user, REPOS_PATH, 1, []).then((repos)=>
{
var minimized = minimizeRepositories(repos);
resolve(minimized);
cache.put(user + REPOS_PATH, minimized);
});
}
else
{
console.log("Repositories cache hit");
resolve(cacheHit);
}
});
}
routes.get("/repositories/:name", (request, result)=>
{
queryRepositories(request.params.name).then(repos=>
{
result.json(repos)
.end();
}).catch(error=>
{
result.status(500)
.json({error: 'API error fetching friends'})
.end();
});
});
routes.get('/*', (request, result) =>

Loading…
Cancel
Save