mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-11 21:30:51 +01:00
Imprement hashtag stats
This commit is contained in:
parent
7bbf022978
commit
4c180869c6
2 changed files with 44 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { IUser } from '../models/user';
|
import { IUser } from '../models/user';
|
||||||
import Hashtag from '../models/hashtag';
|
import Hashtag from '../models/hashtag';
|
||||||
|
import { hashtagStats } from './stats';
|
||||||
|
|
||||||
export default async function(user: IUser, tag: string) {
|
export default async function(user: IUser, tag: string) {
|
||||||
tag = tag.toLowerCase();
|
tag = tag.toLowerCase();
|
||||||
|
@ -25,4 +26,6 @@ export default async function(user: IUser, tag: string) {
|
||||||
mentionedUserIdsCount: 1
|
mentionedUserIdsCount: 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hashtagStats.update(tag, user._id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ abstract class Stats<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
private async getCurrentLog(span: Span, group?: Obj): Promise<Log<T>> {
|
private async getCurrentLog(span: Span, group?: any): Promise<Log<T>> {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const y = now.getFullYear();
|
const y = now.getFullYear();
|
||||||
const m = now.getMonth();
|
const m = now.getMonth();
|
||||||
|
@ -156,7 +156,7 @@ abstract class Stats<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
protected commit(query: Obj, group?: Obj, uniqueKey?: string, uniqueValue?: string): void {
|
protected commit(query: Obj, group?: any, uniqueKey?: string, uniqueValue?: string): void {
|
||||||
const update = (log: Log<T>) => {
|
const update = (log: Log<T>) => {
|
||||||
// ユニークインクリメントの場合、指定のキーに指定の値が既に存在していたら弾く
|
// ユニークインクリメントの場合、指定のキーに指定の値が既に存在していたら弾く
|
||||||
if (
|
if (
|
||||||
|
@ -183,21 +183,21 @@ abstract class Stats<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
protected inc(inc: Partial<T>, group?: Obj): void {
|
protected inc(inc: Partial<T>, group?: any): void {
|
||||||
this.commit({
|
this.commit({
|
||||||
$inc: this.convertQuery(inc, 'data')
|
$inc: this.convertQuery(inc, 'data')
|
||||||
}, group);
|
}, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
protected incIfUnique(inc: Partial<T>, key: string, value: string, group?: Obj): void {
|
protected incIfUnique(inc: Partial<T>, key: string, value: string, group?: any): void {
|
||||||
this.commit({
|
this.commit({
|
||||||
$inc: this.convertQuery(inc, 'data')
|
$inc: this.convertQuery(inc, 'data')
|
||||||
}, group, key, value);
|
}, group, key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
public async getChart(span: Span, range: number, group?: Obj): Promise<ArrayValue<T>> {
|
public async getChart(span: Span, range: number, group?: any): Promise<ArrayValue<T>> {
|
||||||
const promisedChart: Promise<T>[] = [];
|
const promisedChart: Promise<T>[] = [];
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
@ -730,3 +730,39 @@ class NetworkStats extends Stats<NetworkLog> {
|
||||||
|
|
||||||
export const networkStats = new NetworkStats();
|
export const networkStats = new NetworkStats();
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
//#region Hashtag stats
|
||||||
|
/**
|
||||||
|
* ハッシュタグに関する統計
|
||||||
|
*/
|
||||||
|
type HashtagLog = {
|
||||||
|
/**
|
||||||
|
* 投稿された数
|
||||||
|
*/
|
||||||
|
count: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
class HashtagStats extends Stats<HashtagLog> {
|
||||||
|
constructor() {
|
||||||
|
super('hashtag');
|
||||||
|
}
|
||||||
|
|
||||||
|
@autobind
|
||||||
|
protected async generateTemplate(init: boolean, latestLog?: HashtagLog): Promise<HashtagLog> {
|
||||||
|
return {
|
||||||
|
count: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@autobind
|
||||||
|
public async update(hashtag: string, userId: mongo.ObjectId) {
|
||||||
|
const inc: Partial<HashtagLog> = {
|
||||||
|
count: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
await this.incIfUnique(inc, 'users', userId.toHexString(), hashtag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const hashtagStats = new HashtagStats();
|
||||||
|
//#endregion
|
||||||
|
|
Loading…
Reference in a new issue