1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-11-23 22:56:49 +09:00

fix(api/users): ページビューの並び替えが正常に計算されない問題を修正 (MisskeyIO#728)

This commit is contained in:
まっちゃとーにゅ 2024-09-16 21:34:56 +09:00 committed by GitHub
parent d6f5783e7d
commit 1400dbfd2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 25 deletions

View File

@ -54,10 +54,10 @@ export default class PerUserPvChart extends Chart<typeof schema> { // eslint-dis
} }
@bindThis @bindThis
public async getChartUsers(span: 'hour' | 'day', amount: number, cursor: Date | null, limit = 0, offset = 0): Promise<{ public async getChartUsers(span: 'hour' | 'day', order: 'ASC' | 'DESC', amount: number, cursor: Date | null, limit = 0, offset = 0): Promise<{
userId: string; userId: string;
count: number; count: number;
}[]> { }[]> {
return await this.getChartPv(span, amount, cursor, limit, offset); return await this.getChartPv(span, amount, cursor, limit, offset, order);
} }
} }

View File

@ -727,7 +727,7 @@ export default abstract class Chart<T extends Schema> {
} }
@bindThis @bindThis
public async getChartPv(span: 'hour' | 'day', amount: number, cursor: Date | null, limit: number, offset: number): Promise< public async getChartPv(span: 'hour' | 'day', amount: number, cursor: Date | null, limit: number, offset: number, order: 'ASC' | 'DESC'): Promise<
{ {
userId: string, userId: string,
count: number, count: number,
@ -749,27 +749,13 @@ export default abstract class Chart<T extends Schema> {
new Error('not happen') as never; new Error('not happen') as never;
// ログ取得 // ログ取得
const logs = await repository.createQueryBuilder() return await repository.createQueryBuilder()
.select('"group" as "userId", sum("___upv_user" + "___upv_visitor") as "count"')
.where('date BETWEEN :gt AND :lt', { gt: Chart.dateToTimestamp(gt), lt: Chart.dateToTimestamp(lt) }) .where('date BETWEEN :gt AND :lt', { gt: Chart.dateToTimestamp(gt), lt: Chart.dateToTimestamp(lt) })
.orderBy('___pv_visitor + ___upv_visitor + ___pv_user + ___upv_user', 'DESC') .groupBy('"userId"')
.skip(offset) .orderBy('"count"', order)
.take(limit) .offset(offset)
.getMany() as { .limit(limit)
___pv_visitor: number, .getRawMany<{ userId: string, count: number }>();
___upv_visitor: number,
___pv_user: number,
___upv_user: number,
group: string,
}[];
const result = [] as {
userId: string,
count: number,
}[];
for (const row of logs) {
const userId = row.group;
const count = row.___pv_user + row.___upv_user + row.___pv_visitor + row.___upv_visitor;
result.push({ userId, count });
}
return result;
} }
} }

View File

@ -74,7 +74,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
} }
const chartUsers: { userId: string; count: number; }[] = []; const chartUsers: { userId: string; count: number; }[] = [];
if (ps.sort?.endsWith('pv')) { if (ps.sort?.endsWith('pv')) {
await this.perUserPvChart.getChartUsers('hour', 0, null, ps.limit, ps.offset).then(users => { await this.perUserPvChart.getChartUsers('hour', ps.sort === '+pv' ? 'DESC' : 'ASC', 0, null, ps.limit, ps.offset).then(users => {
chartUsers.push(...users); chartUsers.push(...users);
}); });
} }