fix(api/users): PVランキングに誰もいない場合エラーになる問題を修正 (MisskeyIO#737)
This commit is contained in:
parent
8e9b6dc4d1
commit
c82bf7583a
@ -73,10 +73,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||||||
query.andWhere('user.host = :hostname', { hostname: ps.hostname.toLowerCase() });
|
query.andWhere('user.host = :hostname', { hostname: ps.hostname.toLowerCase() });
|
||||||
}
|
}
|
||||||
|
|
||||||
let pvUsers: { userId: string; count: number; }[] | undefined = undefined;
|
let pvRankedUsers: { userId: string; count: number; }[] | undefined = undefined;
|
||||||
if (ps.sort?.endsWith('pv')) {
|
if (ps.sort?.endsWith('pv')) {
|
||||||
// 直近12時間のPVランキングを取得
|
// 直近12時間のPVランキングを取得
|
||||||
pvUsers = await this.perUserPvChart.getUsersRanking(
|
pvRankedUsers = await this.perUserPvChart.getUsersRanking(
|
||||||
'hour', ps.sort.startsWith('+') ? 'DESC' : 'ASC',
|
'hour', ps.sort.startsWith('+') ? 'DESC' : 'ASC',
|
||||||
12, null, ps.limit, ps.offset,
|
12, null, ps.limit, ps.offset,
|
||||||
);
|
);
|
||||||
@ -89,8 +89,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||||||
case '-createdAt': query.orderBy('user.id', 'ASC'); break;
|
case '-createdAt': query.orderBy('user.id', 'ASC'); break;
|
||||||
case '+updatedAt': query.andWhere('user.updatedAt IS NOT NULL').orderBy('user.updatedAt', 'DESC'); break;
|
case '+updatedAt': query.andWhere('user.updatedAt IS NOT NULL').orderBy('user.updatedAt', 'DESC'); break;
|
||||||
case '-updatedAt': query.andWhere('user.updatedAt IS NOT NULL').orderBy('user.updatedAt', 'ASC'); break;
|
case '-updatedAt': query.andWhere('user.updatedAt IS NOT NULL').orderBy('user.updatedAt', 'ASC'); break;
|
||||||
case '+pv': query.andWhere('user.id IN (:...userIds)', { userIds: pvUsers?.map(user => user.userId) ?? [] }); break;
|
case '+pv': query.andWhere((pvRankedUsers?.length ?? 0) > 0 ? 'user.id IN (:...userIds)' : '1 = 0', { userIds: pvRankedUsers?.map(user => user.userId) ?? [] }); break;
|
||||||
case '-pv': query.andWhere('user.id IN (:...userIds)', { userIds: pvUsers?.map(user => user.userId) ?? [] }); break;
|
case '-pv': query.andWhere((pvRankedUsers?.length ?? 0) > 0 ? 'user.id IN (:...userIds)' : '1 = 0', { userIds: pvRankedUsers?.map(user => user.userId) ?? [] }); break;
|
||||||
default: query.orderBy('user.id', 'ASC'); break;
|
default: query.orderBy('user.id', 'ASC'); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,14 +103,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||||||
const users = await query.getMany();
|
const users = await query.getMany();
|
||||||
if (ps.sort === '+pv') {
|
if (ps.sort === '+pv') {
|
||||||
users.sort((a, b) => {
|
users.sort((a, b) => {
|
||||||
const aPv = pvUsers?.find(u => u.userId === a.id)?.count ?? 0;
|
const aPv = pvRankedUsers?.find(u => u.userId === a.id)?.count ?? 0;
|
||||||
const bPv = pvUsers?.find(u => u.userId === b.id)?.count ?? 0;
|
const bPv = pvRankedUsers?.find(u => u.userId === b.id)?.count ?? 0;
|
||||||
return bPv - aPv;
|
return bPv - aPv;
|
||||||
});
|
});
|
||||||
} else if (ps.sort === '-pv') {
|
} else if (ps.sort === '-pv') {
|
||||||
users.sort((a, b) => {
|
users.sort((a, b) => {
|
||||||
const aPv = pvUsers?.find(u => u.userId === a.id)?.count ?? 0;
|
const aPv = pvRankedUsers?.find(u => u.userId === a.id)?.count ?? 0;
|
||||||
const bPv = pvUsers?.find(u => u.userId === b.id)?.count ?? 0;
|
const bPv = pvRankedUsers?.find(u => u.userId === b.id)?.count ?? 0;
|
||||||
return aPv - bPv;
|
return aPv - bPv;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user