統計で無視するハッシュタグを設定できるように

This commit is contained in:
syuilo
2018-09-07 19:20:50 +09:00
parent 106d4cc0d6
commit 7343e6e2e8
6 changed files with 74 additions and 6 deletions

View File

@ -21,7 +21,13 @@ export const meta = {
desc: {
'ja-JP': '招待制か否か'
}
})
}),
hidedTags: $.arr($.str).optional.nullable.note({
desc: {
'ja-JP': '統計などで無視するハッシュタグ'
}
}),
}
};
@ -39,6 +45,10 @@ export default (params: any) => new Promise(async (res, rej) => {
set.disableRegistration = ps.disableRegistration;
}
if (Array.isArray(ps.hidedTags)) {
set.hidedTags = ps.hidedTags;
}
await Meta.update({}, {
$set: set
}, { upsert: true });

View File

@ -1,5 +1,6 @@
import Note from '../../../../models/note';
import { erase } from '../../../../prelude/array';
import Meta from '../../../../models/meta';
/*
トレンドに載るためには「『直近a分間のユニーク投稿数が今からa分前今からb分前の間のユニーク投稿数のn倍以上』のハッシュタグの上位5位以内に入る」ことが必要
@ -17,6 +18,9 @@ const max = 5;
* Get trends of hashtags
*/
export default () => new Promise(async (res, rej) => {
const meta = await Meta.findOne({});
const hidedTags = (meta.hidedTags || []).map(t => t.toLowerCase());
//#region 1. 直近Aの内に投稿されたハッシュタグ(とユーザーのペア)を集計
const data = await Note.aggregate([{
$match: {
@ -53,6 +57,9 @@ export default () => new Promise(async (res, rej) => {
// カウント
data.map(x => x._id).forEach(x => {
// ブラックリストに登録されているタグなら弾く
if (hidedTags.includes(x.tag)) return;
const i = tags.findIndex(tag => tag.name == x.tag);
if (i != -1) {
tags[i].count++;

View File

@ -4,6 +4,7 @@
import * as os from 'os';
import config from '../../../config';
import Meta from '../../../models/meta';
import { ILocalUser } from '../../../models/user';
const pkg = require('../../../../package.json');
const client = require('../../../../built/client/meta.json');
@ -11,7 +12,7 @@ const client = require('../../../../built/client/meta.json');
/**
* Show core info
*/
export default () => new Promise(async (res, rej) => {
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
const meta: any = (await Meta.findOne()) || {};
res({
@ -35,6 +36,7 @@ export default () => new Promise(async (res, rej) => {
disableRegistration: meta.disableRegistration,
driveCapacityPerLocalUserMb: config.localDriveCapacityMb,
recaptchaSitekey: config.recaptcha ? config.recaptcha.site_key : null,
swPublickey: config.sw ? config.sw.public_key : null
swPublickey: config.sw ? config.sw.public_key : null,
hidedTags: (me && me.isAdmin) ? meta.hidedTags : undefined
});
});