fix(api/users): PVランキングに誰もいない場合エラーになる問題を修正 (MisskeyIO#737)
(cherry picked from commit c82bf7583a)
			
			
This commit is contained in:
		
							parent
							
								
									0ed2b06bc4
								
							
						
					
					
						commit
						d1d4bf1c19
					
				|  | @ -73,10 +73,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | |||
| 				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')) { | ||||
| 				// 直近12時間のPVランキングを取得
 | ||||
| 				pvUsers = await this.perUserPvChart.getUsersRanking( | ||||
| 				pvRankedUsers = await this.perUserPvChart.getUsersRanking( | ||||
| 					'hour', ps.sort.startsWith('+') ? 'DESC' : 'ASC', | ||||
| 					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 '+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 '+pv': query.andWhere('user.id IN (:...userIds)', { userIds: pvUsers?.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; | ||||
| 				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; | ||||
| 			} | ||||
| 
 | ||||
|  | @ -103,14 +103,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | |||
| 			const users = await query.getMany(); | ||||
| 			if (ps.sort === '+pv') { | ||||
| 				users.sort((a, b) => { | ||||
| 					const aPv = pvUsers?.find(u => u.userId === a.id)?.count ?? 0; | ||||
| 					const bPv = pvUsers?.find(u => u.userId === b.id)?.count ?? 0; | ||||
| 					const aPv = pvRankedUsers?.find(u => u.userId === a.id)?.count ?? 0; | ||||
| 					const bPv = pvRankedUsers?.find(u => u.userId === b.id)?.count ?? 0; | ||||
| 					return bPv - aPv; | ||||
| 				}); | ||||
| 			} else if (ps.sort === '-pv') { | ||||
| 				users.sort((a, b) => { | ||||
| 					const aPv = pvUsers?.find(u => u.userId === a.id)?.count ?? 0; | ||||
| 					const bPv = pvUsers?.find(u => u.userId === b.id)?.count ?? 0; | ||||
| 					const aPv = pvRankedUsers?.find(u => u.userId === a.id)?.count ?? 0; | ||||
| 					const bPv = pvRankedUsers?.find(u => u.userId === b.id)?.count ?? 0; | ||||
| 					return aPv - bPv; | ||||
| 				}); | ||||
| 			} | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue