Skip to content

Commit 8dd4e37

Browse files
committed
fix: limit top contributors amount to 25 in coalition pages
1 parent 6b417f7 commit 8dd4e37

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/routes/home.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export const setupHomeRoutes = function(app: Express, prisma: PrismaClient): voi
123123
return res.status(400).send('Invalid coalition ID');
124124
}
125125
const user = req.user as ExpressIntraUser;
126+
const now = new Date();
126127

127128
const coalition = await prisma.codamCoalition.findFirst({
128129
where: {
@@ -136,17 +137,17 @@ export const setupHomeRoutes = function(app: Express, prisma: PrismaClient): voi
136137
return res.status(404).send('Coalition not found');
137138
}
138139

139-
const bloc = await getBlocAtDate(prisma, new Date());
140+
const bloc = await getBlocAtDate(prisma, now);
140141
if (!bloc) {
141142
// No ongoing season, there's no point in viewing this page. Redirect to home.
142143
return res.redirect('/');
143144
}
144145

145-
// Get the top contributors of this seasona
146-
const topContributors = await getCoalitionTopContributors(prisma, coalition.id, 'Top contributors of this season');
146+
// Get the top 25 contributors of this season
147+
const topContributors = await getCoalitionTopContributors(prisma, coalition.id, 'Top contributors of this season', now, 25);
147148

148149
// Get the top contributors of the past 7 days
149-
const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
150+
const sevenDaysAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
150151
if (sevenDaysAgo < bloc.begin_at) {
151152
// If the season started less than 7 days ago, we can't get the top contributors of the past 7 days.
152153
// Get the top contributors since the season's start instead.
@@ -167,7 +168,7 @@ export const setupHomeRoutes = function(app: Express, prisma: PrismaClient): voi
167168
coalition_id: coalition.id,
168169
created_at: {
169170
gte: sevenDaysAgo,
170-
lte: new Date(),
171+
lte: now,
171172
},
172173
},
173174
take: 10,
@@ -217,7 +218,7 @@ export const setupHomeRoutes = function(app: Express, prisma: PrismaClient): voi
217218
},
218219
created_at: {
219220
gte: sevenDaysAgo,
220-
lte: new Date(),
221+
lte: now,
221222
},
222223
},
223224
orderBy: {

0 commit comments

Comments
 (0)