diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-10-23 09:59:43 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-10-23 09:59:43 +0900 |
| commit | 11c5d257f2394a8a9dcfc7fe15c9e57684dfd11e (patch) | |
| tree | bb01289dceb1472924910a9593a36ae36b5059ed /src/chart | |
| parent | :art: (diff) | |
| download | sharkey-11c5d257f2394a8a9dcfc7fe15c9e57684dfd11e.tar.gz sharkey-11c5d257f2394a8a9dcfc7fe15c9e57684dfd11e.tar.bz2 sharkey-11c5d257f2394a8a9dcfc7fe15c9e57684dfd11e.zip | |
ハッシュタグチャートでローカルとリモートを分離するように
Diffstat (limited to 'src/chart')
| -rw-r--r-- | src/chart/hashtag.ts | 39 |
1 files changed, 29 insertions, 10 deletions
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<HashtagLog> { 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<HashtagLog> { return { - count: 0 + local: { + count: 0 + }, + remote: { + count: 0 + } }; } @autobind - public async update(hashtag: string, userId: mongo.ObjectId) { - const inc: Partial<HashtagLog> = { + 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); } } |