forked from misskey-dev/misskey
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/backend/migration/1672562400597-PerUserPvChart.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export class PerUserPvChart1672562400597 { | ||
name = 'PerUserPvChart1672562400597' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`CREATE TABLE "__chart__per_user_pv" ("id" SERIAL NOT NULL, "date" integer NOT NULL, "group" character varying(128) NOT NULL, "unique_temp___upv_user" character varying array NOT NULL DEFAULT '{}', "___upv_user" smallint NOT NULL DEFAULT '0', "___pv_user" smallint NOT NULL DEFAULT '0', "unique_temp___upv_visitor" character varying array NOT NULL DEFAULT '{}', "___upv_visitor" smallint NOT NULL DEFAULT '0', "___pv_visitor" smallint NOT NULL DEFAULT '0', CONSTRAINT "UQ_f2a56da57921ca8439f45c1d95f" UNIQUE ("date", "group"), CONSTRAINT "PK_3c938a24f0203b5bd13fab51059" PRIMARY KEY ("id"))`); | ||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_f2a56da57921ca8439f45c1d95" ON "__chart__per_user_pv" ("date", "group") `); | ||
await queryRunner.query(`CREATE TABLE "__chart_day__per_user_pv" ("id" SERIAL NOT NULL, "date" integer NOT NULL, "group" character varying(128) NOT NULL, "unique_temp___upv_user" character varying array NOT NULL DEFAULT '{}', "___upv_user" smallint NOT NULL DEFAULT '0', "___pv_user" smallint NOT NULL DEFAULT '0', "unique_temp___upv_visitor" character varying array NOT NULL DEFAULT '{}', "___upv_visitor" smallint NOT NULL DEFAULT '0', "___pv_visitor" smallint NOT NULL DEFAULT '0', CONSTRAINT "UQ_f221e45cfac5bea0ce0f3149fbb" UNIQUE ("date", "group"), CONSTRAINT "PK_0085d7542f6772e99b9dcfb0a9c" PRIMARY KEY ("id"))`); | ||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_f221e45cfac5bea0ce0f3149fb" ON "__chart_day__per_user_pv" ("date", "group") `); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`DROP INDEX "public"."IDX_f221e45cfac5bea0ce0f3149fb"`); | ||
await queryRunner.query(`DROP TABLE "__chart_day__per_user_pv"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_f2a56da57921ca8439f45c1d95"`); | ||
await queryRunner.query(`DROP TABLE "__chart__per_user_pv"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/backend/src/core/chart/charts/entities/per-user-pv.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Chart from '../../core.js'; | ||
|
||
export const name = 'perUserPv'; | ||
|
||
export const schema = { | ||
'upv.user': { uniqueIncrement: true, range: 'small' }, | ||
'pv.user': { range: 'small' }, | ||
'upv.visitor': { uniqueIncrement: true, range: 'small' }, | ||
'pv.visitor': { range: 'small' }, | ||
} as const; | ||
|
||
export const entity = Chart.schemaToEntity(name, schema, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Injectable, Inject } from '@nestjs/common'; | ||
import { DataSource } from 'typeorm'; | ||
import type { User } from '@/models/entities/User.js'; | ||
import { AppLockService } from '@/core/AppLockService.js'; | ||
import { DI } from '@/di-symbols.js'; | ||
import { bindThis } from '@/decorators.js'; | ||
import Chart from '../core.js'; | ||
import { ChartLoggerService } from '../ChartLoggerService.js'; | ||
import { name, schema } from './entities/per-user-pv.js'; | ||
import type { KVs } from '../core.js'; | ||
|
||
/** | ||
* ユーザーごとのプロフィール被閲覧数に関するチャート | ||
*/ | ||
// eslint-disable-next-line import/no-default-export | ||
@Injectable() | ||
export default class PerUserPvChart extends Chart<typeof schema> { | ||
constructor( | ||
@Inject(DI.db) | ||
private db: DataSource, | ||
|
||
private appLockService: AppLockService, | ||
private chartLoggerService: ChartLoggerService, | ||
) { | ||
super(db, (k) => appLockService.getChartInsertLock(k), chartLoggerService.logger, name, schema, true); | ||
} | ||
|
||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> { | ||
return {}; | ||
} | ||
|
||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> { | ||
return {}; | ||
} | ||
|
||
@bindThis | ||
public async commitByUser(user: { id: User['id'] }, key: string): Promise<void> { | ||
await this.commit({ | ||
'upv.user': [key], | ||
'pv.user': 1, | ||
}, user.id); | ||
} | ||
|
||
@bindThis | ||
public async commitByVisitor(user: { id: User['id'] }, key: string): Promise<void> { | ||
await this.commit({ | ||
'upv.visitor': [key], | ||
'pv.visitor': 1, | ||
}, user.id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/backend/src/server/api/endpoints/charts/user/pv.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { getJsonSchema } from '@/core/chart/core.js'; | ||
import { Endpoint } from '@/server/api/endpoint-base.js'; | ||
import PerUserPvChart from '@/core/chart/charts/per-user-pv.js'; | ||
import { schema } from '@/core/chart/charts/entities/per-user-notes.js'; | ||
|
||
export const meta = { | ||
tags: ['charts', 'users'], | ||
|
||
res: getJsonSchema(schema), | ||
|
||
allowGet: true, | ||
cacheSec: 60 * 60, | ||
} as const; | ||
|
||
export const paramDef = { | ||
type: 'object', | ||
properties: { | ||
span: { type: 'string', enum: ['day', 'hour'] }, | ||
limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, | ||
offset: { type: 'integer', nullable: true, default: null }, | ||
userId: { type: 'string', format: 'misskey:id' }, | ||
}, | ||
required: ['span', 'userId'], | ||
} as const; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
@Injectable() | ||
export default class extends Endpoint<typeof meta, typeof paramDef> { | ||
constructor( | ||
private perUserPvChart: PerUserPvChart, | ||
) { | ||
super(meta, paramDef, async (ps, me) => { | ||
return await this.perUserPvChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null, ps.userId); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters