From 11c5d257f2394a8a9dcfc7fe15c9e57684dfd11e Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 23 Oct 2018 09:59:43 +0900 Subject: ハッシュタグチャートでローカルとリモートを分離するように MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chart/hashtag.ts | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'src/chart') diff --git a/src/chart/hashtag.ts b/src/chart/hashtag.ts index 976fd0c84b..5b03d8ba34 100644 --- a/src/chart/hashtag.ts +++ b/src/chart/hashtag.ts @@ -1,36 +1,55 @@ import autobind from 'autobind-decorator'; -import * as mongo from 'mongodb'; -import Chart, { Partial } from './'; +import Chart, { Obj } from './'; +import { IUser, isLocalUser } from '../models/user'; +import db from '../db/mongodb'; /** * ハッシュタグに関するチャート */ type HashtagLog = { - /** - * 投稿された数 - */ - count: number; + local: { + /** + * 投稿された数 + */ + count: number; + }; + + remote: HashtagLog['local']; }; class HashtagChart extends Chart { constructor() { super('hashtag', true); + + // 後方互換性のため + db.get('chart.hashtag').findOne().then(doc => { + if (doc != null && doc.data.local == null) { + db.get('chart.hashtag').drop(); + } + }); } @autobind protected async getTemplate(init: boolean, latest?: HashtagLog): Promise { return { - count: 0 + local: { + count: 0 + }, + remote: { + count: 0 + } }; } @autobind - public async update(hashtag: string, userId: mongo.ObjectId) { - const inc: Partial = { + public async update(hashtag: string, user: IUser) { + const update: Obj = { count: 1 }; - await this.incIfUnique(inc, 'users', userId.toHexString(), hashtag); + await this.incIfUnique({ + [isLocalUser(user) ? 'local' : 'remote']: update + }, 'users', user._id.toHexString(), hashtag); } } -- cgit v1.2.3-freya