summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-06-16 15:23:03 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-06-16 15:23:03 +0900
commit9cac293efc5433f6a2efc7ec7ae3f5244bcfbd0d (patch)
treeb56ffaea869314c44e839a7976d901bdfa202da3
parentnpm install --only=dev するのが既存のドキュメントと互換性が... (diff)
downloadsharkey-9cac293efc5433f6a2efc7ec7ae3f5244bcfbd0d.tar.gz
sharkey-9cac293efc5433f6a2efc7ec7ae3f5244bcfbd0d.tar.bz2
sharkey-9cac293efc5433f6a2efc7ec7ae3f5244bcfbd0d.zip
#1708
-rw-r--r--src/models/note.ts3
-rw-r--r--src/server/api/endpoints/hashtags/trend.ts20
-rw-r--r--src/server/api/endpoints/notes/search_by_tag.ts2
-rw-r--r--src/services/note/create.ts1
4 files changed, 14 insertions, 12 deletions
diff --git a/src/models/note.ts b/src/models/note.ts
index 461bb405a0..21ec2b3857 100644
--- a/src/models/note.ts
+++ b/src/models/note.ts
@@ -16,7 +16,7 @@ import Following from './following';
const Note = db.get<INote>('notes');
Note.createIndex('uri', { sparse: true, unique: true });
Note.createIndex('userId');
-Note.createIndex('tags', { sparse: true });
+Note.createIndex('tagsLower');
Note.createIndex({
createdAt: -1
});
@@ -40,6 +40,7 @@ export type INote = {
poll: any; // todo
text: string;
tags: string[];
+ tagsLower: string[];
cw: string;
userId: mongo.ObjectID;
appId: mongo.ObjectID;
diff --git a/src/server/api/endpoints/hashtags/trend.ts b/src/server/api/endpoints/hashtags/trend.ts
index df7addab98..947dd6e448 100644
--- a/src/server/api/endpoints/hashtags/trend.ts
+++ b/src/server/api/endpoints/hashtags/trend.ts
@@ -7,7 +7,7 @@ import Note from '../../../../models/note';
const rangeA = 1000 * 60 * 30; // 30分
const rangeB = 1000 * 60 * 120; // 2時間
-const coefficient = 1.5; // 「n倍」の部分
+const coefficient = 1.25; // 「n倍」の部分
const requiredUsers = 3; // 最低何人がそのタグを投稿している必要があるか
const max = 5;
@@ -22,20 +22,20 @@ module.exports = () => new Promise(async (res, rej) => {
createdAt: {
$gt: new Date(Date.now() - rangeA)
},
- tags: {
+ tagsLower: {
$exists: true,
$ne: []
}
}
}, {
- $unwind: '$tags'
+ $unwind: '$tagsLower'
}, {
$group: {
- _id: { tags: '$tags', userId: '$userId' }
+ _id: { tag: '$tagsLower', userId: '$userId' }
}
}]) as Array<{
_id: {
- tags: string;
+ tag: string;
userId: any;
}
}>;
@@ -49,12 +49,12 @@ module.exports = () => new Promise(async (res, rej) => {
// カウント
data.map(x => x._id).forEach(x => {
- const i = tags.findIndex(tag => tag.name == x.tags);
+ const i = tags.findIndex(tag => tag.name == x.tag);
if (i != -1) {
tags[i].count++;
} else {
tags.push({
- name: x.tags,
+ name: x.tag,
count: 1
});
}
@@ -66,7 +66,7 @@ module.exports = () => new Promise(async (res, rej) => {
//#region 2. 1で取得したそれぞれのタグについて、「直近a分間のユニーク投稿数が今からa分前~今からb分前の間のユニーク投稿数のn倍以上」かどうかを判定する
const hotsPromises = limitedTags.map(async tag => {
const passedCount = (await Note.distinct('userId', {
- tags: tag.name,
+ tagsLower: tag.name,
createdAt: {
$lt: new Date(Date.now() - rangeA),
$gt: new Date(Date.now() - rangeB)
@@ -108,7 +108,7 @@ module.exports = () => new Promise(async (res, rej) => {
for (let i = 0; i < range; i++) {
countPromises.push(Promise.all(hots.map(tag => Note.distinct('userId', {
- tags: tag,
+ tagsLower: tag,
createdAt: {
$lt: new Date(Date.now() - (interval * i)),
$gt: new Date(Date.now() - (interval * (i + 1)))
@@ -119,7 +119,7 @@ module.exports = () => new Promise(async (res, rej) => {
const countsLog = await Promise.all(countPromises);
const totalCounts: any = await Promise.all(hots.map(tag => Note.distinct('userId', {
- tags: tag,
+ tagsLower: tag,
createdAt: {
$gt: new Date(Date.now() - (interval * range))
}
diff --git a/src/server/api/endpoints/notes/search_by_tag.ts b/src/server/api/endpoints/notes/search_by_tag.ts
index 4cf070f4ce..1eb4cde49c 100644
--- a/src/server/api/endpoints/notes/search_by_tag.ts
+++ b/src/server/api/endpoints/notes/search_by_tag.ts
@@ -101,7 +101,7 @@ async function search(
let q: any = {
$and: [{
- tags: tag
+ tagsLower: tag.toLowerCase()
}]
};
diff --git a/src/services/note/create.ts b/src/services/note/create.ts
index b21bfa316e..98415b8971 100644
--- a/src/services/note/create.ts
+++ b/src/services/note/create.ts
@@ -130,6 +130,7 @@ export default async (user: IUser, data: {
poll: data.poll,
cw: data.cw == null ? null : data.cw,
tags,
+ tagsLower: tags.map(tag => tag.toLowerCase()),
userId: user._id,
viaMobile: data.viaMobile,
geo: data.geo || null,