Skip to content

Commit d9519f8

Browse files
committed
Only reference contributors with a universe
1 parent d448100 commit d9519f8

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

routes/cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function(req, res, next){
3434
res.set('Cache-Control', `public, max-age=60, stale-while-revalidate=${cdn_cache}`);
3535

3636
if(doc){
37-
const revision = 12; // bump to invalidate all caches
37+
const revision = 13; // bump to invalidate all caches
3838
const etag = `W/"${doc._id}${revision}"`;
3939
const date = new Date(doc._published.getTime() + revision * 1000).toUTCString();
4040
res.set('ETag', etag);

routes/universe.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import express from 'express';
22
import url from 'node:url';
3-
import {get_universe_packages, get_universe_vignettes, get_package_info, get_universe_contributors, get_universe_contributions} from '../src/db.js';
3+
import {get_universe_packages, get_universe_vignettes, get_package_info,
4+
get_universe_contributors, get_universe_contributions, get_all_universes} from '../src/db.js';
45
const router = express.Router();
56

67
function sort_by_package(x,y){
@@ -94,10 +95,8 @@ function retry_url(x){
9495
function get_contrib_data(user, max = 20){
9596
const p1 = get_universe_contributors(user, 1000);
9697
const p2 = get_universe_contributions(user, 1000);
97-
return Promise.all([p1, p2]).then(function([contributors, contributions]){
98-
if(contributions.length == 0){
99-
return contributors.slice(0,max); //org users dont make contributions themselves
100-
}
98+
const p3 = get_all_universes();
99+
return Promise.all([p1, p2, p3]).then(function([contributors, contributions, universes]){
101100
var data = contributors.map(function(x){
102101
x.contributions = 0;
103102
x.packages = [];
@@ -114,7 +113,11 @@ function get_contrib_data(user, max = 20){
114113
rec.packages = rec.packages.concat(x.packages);
115114
});
116115
});
117-
return data.sort(function(x,y){return (x.total + x.contributions > y.total + y.contributions) ? -1 : 1}).filter(x => x.login != user).slice(0,max);
116+
return data.filter(function(x){
117+
return x.login != user && universes.includes(x.login);
118+
}).sort(function(x,y){
119+
return (x.total + x.contributions > y.total + y.contributions) ? -1 : 1}
120+
).slice(0, max);
118121
});
119122
}
120123

src/db.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ export function get_all_universes(){
666666
if(production){
667667
return universes;
668668
} else {
669+
//TODO: this does not include maintainer-only universes, but production does
669670
return get_json('https://r-universe.dev/api/universes').then(function(data){
670671
return data.map(x => x.universe);
671672
});

0 commit comments

Comments
 (0)