mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-12-05 10:18:38 +09:00
Improve user search
This commit is contained in:
parent
44cd1e9223
commit
d692bb3c52
@ -40,6 +40,7 @@ async function byNative(res, rej, me, query, offset, max) {
|
|||||||
// Search users
|
// Search users
|
||||||
const users = await User
|
const users = await User
|
||||||
.find({
|
.find({
|
||||||
|
host: null,
|
||||||
$or: [{
|
$or: [{
|
||||||
usernameLower: new RegExp(escapedQuery.replace('@', '').toLowerCase())
|
usernameLower: new RegExp(escapedQuery.replace('@', '').toLowerCase())
|
||||||
}, {
|
}, {
|
||||||
|
@ -20,15 +20,27 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
const users = await User
|
let users = await User
|
||||||
.find({
|
.find({
|
||||||
|
host: null,
|
||||||
usernameLower: new RegExp(query.toLowerCase())
|
usernameLower: new RegExp(query.toLowerCase())
|
||||||
}, {
|
}, {
|
||||||
limit: limit,
|
limit: limit,
|
||||||
skip: offset
|
skip: offset
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (users.length < limit) {
|
||||||
|
const remoteUsers = await User
|
||||||
|
.find({
|
||||||
|
host: { $ne: null },
|
||||||
|
usernameLower: new RegExp(query.toLowerCase())
|
||||||
|
}, {
|
||||||
|
limit: limit - users.length
|
||||||
|
});
|
||||||
|
|
||||||
|
users = users.concat(remoteUsers);
|
||||||
|
}
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
res(await Promise.all(users.map(async user =>
|
res(await Promise.all(users.map(user => pack(user, me, { detail: true }))));
|
||||||
await pack(user, me, { detail: true }))));
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user