Implemet per user notes stats
This commit is contained in:
parent
59266b3190
commit
b8c56c4dda
|
@ -23,7 +23,7 @@ import registerHashtag from '../register-hashtag';
|
|||
import isQuote from '../../misc/is-quote';
|
||||
import { TextElementMention } from '../../mfm/parse/elements/mention';
|
||||
import { TextElementHashtag } from '../../mfm/parse/elements/hashtag';
|
||||
import { notesStats } from '../stats';
|
||||
import { notesStats, perUserNotesStats } from '../stats';
|
||||
import { erase, unique } from '../../prelude/array';
|
||||
import insertNoteUnread from './unread';
|
||||
|
||||
|
@ -166,6 +166,7 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
|
|||
|
||||
// 統計を更新
|
||||
notesStats.update(note, true);
|
||||
perUserNotesStats.update(user, note, true);
|
||||
|
||||
// ハッシュタグ登録
|
||||
tags.map(tag => registerHashtag(user, tag));
|
||||
|
|
|
@ -6,7 +6,7 @@ import pack from '../../remote/activitypub/renderer';
|
|||
import { deliver } from '../../queue';
|
||||
import Following from '../../models/following';
|
||||
import renderTombstone from '../../remote/activitypub/renderer/tombstone';
|
||||
import { notesStats } from '../stats';
|
||||
import { notesStats, perUserNotesStats } from '../stats';
|
||||
import config from '../../config';
|
||||
import NoteUnread from '../../models/note-unread';
|
||||
import read from './read';
|
||||
|
@ -64,4 +64,5 @@ export default async function(user: IUser, note: INote) {
|
|||
|
||||
// 統計を更新
|
||||
notesStats.update(note, false);
|
||||
perUserNotesStats.update(user, note, false);
|
||||
}
|
||||
|
|
|
@ -819,3 +819,95 @@ class FollowingStats extends Stats<FollowingLog> {
|
|||
|
||||
export const followingStats = new FollowingStats();
|
||||
//#endregion
|
||||
|
||||
//#region Per user notes stats
|
||||
/**
|
||||
* ユーザーごとの投稿に関する統計
|
||||
*/
|
||||
type PerUserNotesLog = {
|
||||
/**
|
||||
* 集計期間時点での、全投稿数
|
||||
*/
|
||||
total: number;
|
||||
|
||||
/**
|
||||
* 増加した投稿数
|
||||
*/
|
||||
inc: number;
|
||||
|
||||
/**
|
||||
* 減少した投稿数
|
||||
*/
|
||||
dec: number;
|
||||
|
||||
diffs: {
|
||||
/**
|
||||
* 通常の投稿数の差分
|
||||
*/
|
||||
normal: number;
|
||||
|
||||
/**
|
||||
* リプライの投稿数の差分
|
||||
*/
|
||||
reply: number;
|
||||
|
||||
/**
|
||||
* Renoteの投稿数の差分
|
||||
*/
|
||||
renote: number;
|
||||
};
|
||||
};
|
||||
|
||||
class PerUserNotesStats extends Stats<PerUserNotesLog> {
|
||||
constructor() {
|
||||
super('notes');
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async getTemplate(init: boolean, latest?: PerUserNotesLog, group?: any): Promise<PerUserNotesLog> {
|
||||
const [count] = init ? await Promise.all([
|
||||
Note.count({ userId: group, deletedAt: null }),
|
||||
]) : [
|
||||
latest ? latest.total : 0
|
||||
];
|
||||
|
||||
return {
|
||||
total: count,
|
||||
inc: 0,
|
||||
dec: 0,
|
||||
diffs: {
|
||||
normal: 0,
|
||||
reply: 0,
|
||||
renote: 0
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: IUser, note: INote, isAdditional: boolean) {
|
||||
const update: Obj = {
|
||||
diffs: {}
|
||||
};
|
||||
|
||||
update.total = isAdditional ? 1 : -1;
|
||||
|
||||
if (isAdditional) {
|
||||
update.inc = 1;
|
||||
} else {
|
||||
update.dec = 1;
|
||||
}
|
||||
|
||||
if (note.replyId != null) {
|
||||
update.diffs.reply = isAdditional ? 1 : -1;
|
||||
} else if (note.renoteId != null) {
|
||||
update.diffs.renote = isAdditional ? 1 : -1;
|
||||
} else {
|
||||
update.diffs.normal = isAdditional ? 1 : -1;
|
||||
}
|
||||
|
||||
await this.inc(update, user._id);
|
||||
}
|
||||
}
|
||||
|
||||
export const perUserNotesStats = new PerUserNotesStats();
|
||||
//#endregion
|
||||
|
|
Loading…
Reference in New Issue