1
1
import express from 'express' ;
2
2
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' ;
4
5
const router = express . Router ( ) ;
5
6
6
7
function sort_by_package ( x , y ) {
@@ -94,10 +95,8 @@ function retry_url(x){
94
95
function get_contrib_data ( user , max = 20 ) {
95
96
const p1 = get_universe_contributors ( user , 1000 ) ;
96
97
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 ] ) {
101
100
var data = contributors . map ( function ( x ) {
102
101
x . contributions = 0 ;
103
102
x . packages = [ ] ;
@@ -114,7 +113,11 @@ function get_contrib_data(user, max = 20){
114
113
rec . packages = rec . packages . concat ( x . packages ) ;
115
114
} ) ;
116
115
} ) ;
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 ) ;
118
121
} ) ;
119
122
}
120
123
0 commit comments