forked from FoundKeyGang/FoundKey
みつけるの人気のタグを第2ソートで連合含めたユーザー数にしたりユーザーのタグ以外は除外するように
This commit is contained in:
parent
d9092dc81f
commit
0e046faf4a
4 changed files with 91 additions and 8 deletions
|
@ -11,7 +11,8 @@
|
||||||
<template #header><fa :icon="faHashtag" fixed-width/>{{ $t('popular-tags') }}</template>
|
<template #header><fa :icon="faHashtag" fixed-width/>{{ $t('popular-tags') }}</template>
|
||||||
|
|
||||||
<div class="vxjfqztj">
|
<div class="vxjfqztj">
|
||||||
<router-link v-for="tag in tags" :to="`/explore/tags/${tag.tag}`" :key="tag.tag">{{ tag.tag }}</router-link>
|
<router-link v-for="tag in tagsLocal" :to="`/explore/tags/${tag.tag}`" :key="tag.tag" class="local">{{ tag.tag }}</router-link>
|
||||||
|
<router-link v-for="tag in tagsRemote" :to="`/explore/tags/${tag.tag}`" :key="tag.tag">{{ tag.tag }}</router-link>
|
||||||
</div>
|
</div>
|
||||||
</ui-container>
|
</ui-container>
|
||||||
|
|
||||||
|
@ -73,7 +74,8 @@ export default Vue.extend({
|
||||||
sort: '+createdAt',
|
sort: '+createdAt',
|
||||||
limit: 10
|
limit: 10
|
||||||
}),
|
}),
|
||||||
tags: [],
|
tagsLocal: [],
|
||||||
|
tagsRemote: [],
|
||||||
faBookmark, faChartLine, faCommentAlt, faPlus, faHashtag
|
faBookmark, faChartLine, faCommentAlt, faPlus, faHashtag
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -103,9 +105,17 @@ export default Vue.extend({
|
||||||
created() {
|
created() {
|
||||||
this.$root.api('hashtags/list', {
|
this.$root.api('hashtags/list', {
|
||||||
sort: '+attachedLocalUsers',
|
sort: '+attachedLocalUsers',
|
||||||
|
attachedToLocalUserOnly: true,
|
||||||
limit: 30
|
limit: 30
|
||||||
}).then(tags => {
|
}).then(tags => {
|
||||||
this.tags = tags;
|
this.tagsLocal = tags;
|
||||||
|
});
|
||||||
|
this.$root.api('hashtags/list', {
|
||||||
|
sort: '+attachedRemoteUsers',
|
||||||
|
attachedToRemoteUserOnly: true,
|
||||||
|
limit: 30
|
||||||
|
}).then(tags => {
|
||||||
|
this.tagsRemote = tags;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -118,4 +128,7 @@ export default Vue.extend({
|
||||||
> *
|
> *
|
||||||
margin-right 16px
|
margin-right 16px
|
||||||
|
|
||||||
|
&.local
|
||||||
|
font-weight bold
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -5,8 +5,10 @@ const Hashtag = db.get<IHashtags>('hashtags');
|
||||||
Hashtag.createIndex('tag', { unique: true });
|
Hashtag.createIndex('tag', { unique: true });
|
||||||
Hashtag.createIndex('mentionedUsersCount');
|
Hashtag.createIndex('mentionedUsersCount');
|
||||||
Hashtag.createIndex('mentionedLocalUsersCount');
|
Hashtag.createIndex('mentionedLocalUsersCount');
|
||||||
|
Hashtag.createIndex('mentionedRemoteUsersCount');
|
||||||
Hashtag.createIndex('attachedUsersCount');
|
Hashtag.createIndex('attachedUsersCount');
|
||||||
Hashtag.createIndex('attachedLocalUsersCount');
|
Hashtag.createIndex('attachedLocalUsersCount');
|
||||||
|
Hashtag.createIndex('attachedRemoteUsersCount');
|
||||||
export default Hashtag;
|
export default Hashtag;
|
||||||
|
|
||||||
// 後方互換性のため
|
// 後方互換性のため
|
||||||
|
@ -29,6 +31,20 @@ Hashtag.findOne({ attachedUserIds: { $exists: false }}).then(h => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Hashtag.findOne({ attachedRemoteUserIds: { $exists: false }}).then(h => {
|
||||||
|
if (h != null) {
|
||||||
|
Hashtag.update({}, {
|
||||||
|
$set: {
|
||||||
|
mentionedRemoteUserIds: [],
|
||||||
|
mentionedRemoteUsersCount: 0,
|
||||||
|
attachedRemoteUserIds: [],
|
||||||
|
attachedRemoteUsersCount: 0,
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
multi: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export interface IHashtags {
|
export interface IHashtags {
|
||||||
tag: string;
|
tag: string;
|
||||||
|
@ -36,8 +52,12 @@ export interface IHashtags {
|
||||||
mentionedUsersCount: number;
|
mentionedUsersCount: number;
|
||||||
mentionedLocalUserIds: mongo.ObjectID[];
|
mentionedLocalUserIds: mongo.ObjectID[];
|
||||||
mentionedLocalUsersCount: number;
|
mentionedLocalUsersCount: number;
|
||||||
|
mentionedRemoteUserIds: mongo.ObjectID[];
|
||||||
|
mentionedRemoteUsersCount: number;
|
||||||
attachedUserIds: mongo.ObjectID[];
|
attachedUserIds: mongo.ObjectID[];
|
||||||
attachedUsersCount: number;
|
attachedUsersCount: number;
|
||||||
attachedLocalUserIds: mongo.ObjectID[];
|
attachedLocalUserIds: mongo.ObjectID[];
|
||||||
attachedLocalUsersCount: number;
|
attachedLocalUsersCount: number;
|
||||||
|
attachedRemoteUserIds: mongo.ObjectID[];
|
||||||
|
attachedRemoteUsersCount: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,35 @@ export const meta = {
|
||||||
default: 10
|
default: 10
|
||||||
},
|
},
|
||||||
|
|
||||||
|
attachedToUserOnly: {
|
||||||
|
validator: $.optional.bool,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
|
||||||
|
attachedToLocalUserOnly: {
|
||||||
|
validator: $.optional.bool,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
|
||||||
|
attachedToRemoteUserOnly: {
|
||||||
|
validator: $.optional.bool,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
|
||||||
sort: {
|
sort: {
|
||||||
validator: $.str.or([
|
validator: $.str.or([
|
||||||
'+mentionedUsers',
|
'+mentionedUsers',
|
||||||
'-mentionedUsers',
|
'-mentionedUsers',
|
||||||
'+mentionedLocalUsers',
|
'+mentionedLocalUsers',
|
||||||
'-mentionedLocalUsers',
|
'-mentionedLocalUsers',
|
||||||
|
'+mentionedRemoteUsers',
|
||||||
|
'-mentionedRemoteUsers',
|
||||||
'+attachedUsers',
|
'+attachedUsers',
|
||||||
'-attachedUsers',
|
'-attachedUsers',
|
||||||
'+attachedLocalUsers',
|
'+attachedLocalUsers',
|
||||||
'-attachedLocalUsers',
|
'-attachedLocalUsers',
|
||||||
|
'+attachedRemoteUsers',
|
||||||
|
'-attachedRemoteUsers',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -31,23 +50,33 @@ const sort: any = {
|
||||||
'-mentionedUsers': { mentionedUsersCount: 1 },
|
'-mentionedUsers': { mentionedUsersCount: 1 },
|
||||||
'+mentionedLocalUsers': { mentionedLocalUsersCount: -1 },
|
'+mentionedLocalUsers': { mentionedLocalUsersCount: -1 },
|
||||||
'-mentionedLocalUsers': { mentionedLocalUsersCount: 1 },
|
'-mentionedLocalUsers': { mentionedLocalUsersCount: 1 },
|
||||||
|
'+mentionedRemoteUsers': { mentionedRemoteUsersCount: -1 },
|
||||||
|
'-mentionedRemoteUsers': { mentionedRemoteUsersCount: 1 },
|
||||||
'+attachedUsers': { attachedUsersCount: -1 },
|
'+attachedUsers': { attachedUsersCount: -1 },
|
||||||
'-attachedUsers': { attachedUsersCount: 1 },
|
'-attachedUsers': { attachedUsersCount: 1 },
|
||||||
'+attachedLocalUsers': { attachedLocalUsersCount: -1 },
|
'+attachedLocalUsers': { attachedLocalUsersCount: -1 },
|
||||||
'-attachedLocalUsers': { attachedLocalUsersCount: 1 },
|
'-attachedLocalUsers': { attachedLocalUsersCount: 1 },
|
||||||
|
'+attachedRemoteUsers': { attachedRemoteUsersCount: -1 },
|
||||||
|
'-attachedRemoteUsers': { attachedRemoteUsersCount: 1 },
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
||||||
|
const q = {} as any;
|
||||||
|
if (ps.attachedToUserOnly) q.attachedUsersCount = { $ne: 0 };
|
||||||
|
if (ps.attachedToLocalUserOnly) q.attachedLocalUsersCount = { $ne: 0 };
|
||||||
|
if (ps.attachedToRemoteUserOnly) q.attachedRemoteUsersCount = { $ne: 0 };
|
||||||
const tags = await Hashtag
|
const tags = await Hashtag
|
||||||
.find({}, {
|
.find(q, {
|
||||||
limit: ps.limit,
|
limit: ps.limit,
|
||||||
sort: sort[ps.sort],
|
sort: sort[ps.sort],
|
||||||
fields: {
|
fields: {
|
||||||
tag: true,
|
tag: true,
|
||||||
mentionedUsersCount: true,
|
mentionedUsersCount: true,
|
||||||
mentionedLocalUsersCount: true,
|
mentionedLocalUsersCount: true,
|
||||||
|
mentionedRemoteUsersCount: true,
|
||||||
attachedUsersCount: true,
|
attachedUsersCount: true,
|
||||||
attachedLocalUsersCount: true
|
attachedLocalUsersCount: true,
|
||||||
|
attachedRemoteUsersCount: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { IUser, isLocalUser } from '../models/user';
|
import { IUser, isLocalUser, isRemoteUser } from '../models/user';
|
||||||
import Hashtag from '../models/hashtag';
|
import Hashtag from '../models/hashtag';
|
||||||
import hashtagChart from './chart/hashtag';
|
import hashtagChart from './chart/hashtag';
|
||||||
|
|
||||||
|
@ -26,12 +26,20 @@ export async function updateHashtag(user: IUser, tag: string, isUserAttached = f
|
||||||
$push.attachedLocalUserIds = user._id;
|
$push.attachedLocalUserIds = user._id;
|
||||||
$inc.attachedLocalUsersCount = 1;
|
$inc.attachedLocalUsersCount = 1;
|
||||||
}
|
}
|
||||||
|
// 自分が(リモートで)初めてこのタグを使ったなら
|
||||||
|
if (isRemoteUser(user) && !index.attachedRemoteUserIds.some(id => id.equals(user._id))) {
|
||||||
|
$push.attachedRemoteUserIds = user._id;
|
||||||
|
$inc.attachedRemoteUsersCount = 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$pull.attachedUserIds = user._id;
|
$pull.attachedUserIds = user._id;
|
||||||
$inc.attachedUsersCount = -1;
|
$inc.attachedUsersCount = -1;
|
||||||
if (isLocalUser(user)) {
|
if (isLocalUser(user)) {
|
||||||
$pull.attachedLocalUserIds = user._id;
|
$pull.attachedLocalUserIds = user._id;
|
||||||
$inc.attachedLocalUsersCount = -1;
|
$inc.attachedLocalUsersCount = -1;
|
||||||
|
} else {
|
||||||
|
$pull.attachedRemoteUserIds = user._id;
|
||||||
|
$inc.attachedRemoteUsersCount = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -45,6 +53,11 @@ export async function updateHashtag(user: IUser, tag: string, isUserAttached = f
|
||||||
$push.mentionedLocalUserIds = user._id;
|
$push.mentionedLocalUserIds = user._id;
|
||||||
$inc.mentionedLocalUsersCount = 1;
|
$inc.mentionedLocalUsersCount = 1;
|
||||||
}
|
}
|
||||||
|
// 自分が(リモートで)初めてこのタグを使ったなら
|
||||||
|
if (isRemoteUser(user) && !index.mentionedRemoteUserIds.some(id => id.equals(user._id))) {
|
||||||
|
$push.mentionedRemoteUserIds = user._id;
|
||||||
|
$inc.mentionedRemoteUsersCount = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const q = {} as any;
|
const q = {} as any;
|
||||||
|
@ -60,10 +73,14 @@ export async function updateHashtag(user: IUser, tag: string, isUserAttached = f
|
||||||
mentionedUsersCount: 0,
|
mentionedUsersCount: 0,
|
||||||
mentionedLocalUserIds: [],
|
mentionedLocalUserIds: [],
|
||||||
mentionedLocalUsersCount: 0,
|
mentionedLocalUsersCount: 0,
|
||||||
|
mentionedRemoteUserIds: [],
|
||||||
|
mentionedRemoteUsersCount: 0,
|
||||||
attachedUserIds: [user._id],
|
attachedUserIds: [user._id],
|
||||||
attachedUsersCount: 1,
|
attachedUsersCount: 1,
|
||||||
attachedLocalUserIds: isLocalUser(user) ? [user._id] : [],
|
attachedLocalUserIds: isLocalUser(user) ? [user._id] : [],
|
||||||
attachedLocalUsersCount: isLocalUser(user) ? 1 : 0
|
attachedLocalUsersCount: isLocalUser(user) ? 1 : 0,
|
||||||
|
attachedRemoteUserIds: isRemoteUser(user) ? [user._id] : [],
|
||||||
|
attachedRemoteUsersCount: isRemoteUser(user) ? 1 : 0,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Hashtag.insert({
|
Hashtag.insert({
|
||||||
|
@ -72,10 +89,14 @@ export async function updateHashtag(user: IUser, tag: string, isUserAttached = f
|
||||||
mentionedUsersCount: 1,
|
mentionedUsersCount: 1,
|
||||||
mentionedLocalUserIds: isLocalUser(user) ? [user._id] : [],
|
mentionedLocalUserIds: isLocalUser(user) ? [user._id] : [],
|
||||||
mentionedLocalUsersCount: isLocalUser(user) ? 1 : 0,
|
mentionedLocalUsersCount: isLocalUser(user) ? 1 : 0,
|
||||||
|
mentionedRemoteUserIds: isRemoteUser(user) ? [user._id] : [],
|
||||||
|
mentionedRemoteUsersCount: isRemoteUser(user) ? 1 : 0,
|
||||||
attachedUserIds: [],
|
attachedUserIds: [],
|
||||||
attachedUsersCount: 0,
|
attachedUsersCount: 0,
|
||||||
attachedLocalUserIds: [],
|
attachedLocalUserIds: [],
|
||||||
attachedLocalUsersCount: 0
|
attachedLocalUsersCount: 0,
|
||||||
|
attachedRemoteUserIds: [],
|
||||||
|
attachedRemoteUsersCount: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue