Browse Source

Refactored queryRepositories()

pull/28/head
Peter Morgan 4 years ago
parent
commit
7966131582
1 changed files with 15 additions and 23 deletions
  1. +15
    -23
      routes/api/v2.js

+ 15
- 23
routes/api/v2.js View File

@ -209,30 +209,22 @@ function minimizeRepositories(repositories)
* @param {*} user name of org/user * @param {*} user name of org/user
* @param {*} orgsOrUsers either /users/ or /orgs/ * @param {*} orgsOrUsers either /users/ or /orgs/
*/ */
function queryRepositories(user, orgsOrUsers)
{
const queryRepositories = async (user, orgsOrUsers) => {
const cacheHit = cache.get(user + REPOS_PATH); const cacheHit = cache.get(user + REPOS_PATH);
return new Promise((resolve, reject)=>
{
if(cacheHit == null)
{
fetchAllWithPagination(orgsOrUsers + user + REPOS_PATH, 1, []).then((repos)=>
{
var minimized = minimizeRepositories(repos);
resolve(minimized);
cache.put(user + REPOS_PATH, minimized);
}).catch((err)=>
{
console.log(err)
console.log("bad things went down");
})
}
else
{
console.log("Repositories cache hit");
resolve(cacheHit);
}
});
if (cacheHit) {
console.log("Repositories cache hit");
return cacheHit;
}
try {
const repos = await fetchAllWithPagination(orgsOrUsers + user + REPOS_PATH, 1, []);
const minRepos = minimizeRepositories(repos);
cache.put(`${user}${REPOS_PATH}`, minRepos);
return minRepos;
} catch (error) {
console.log(error)
console.log("bad things went down");
}
} }

Loading…
Cancel
Save