Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import $ from 'cafy'; import ID from '../../../../misc/cafy-id'; | ||
import { ILocalUser, getRelation } from '../../../../models/user'; | ||
import getParams from '../../get-params'; | ||
|
||
export const meta = { | ||
desc: { | ||
'ja-JP': 'ユーザー間のリレーションを取得します。' | ||
}, | ||
|
||
params: { | ||
userId: $.or($.type(ID), $.arr($.type(ID)).unique()).note({ | ||
desc: { | ||
'ja-JP': 'ユーザーID (配列でも可)' | ||
} | ||
}) | ||
} | ||
}; | ||
|
||
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { | ||
const [ps, psErr] = getParams(meta, params); | ||
if (psErr) return rej(psErr); | ||
|
||
const ids = Array.isArray(ps.userId) ? ps.userId : [ps.userId]; | ||
|
||
const relations = await Promise.all(ids.map(id => getRelation(me._id, id))); | ||
|
||
res(Array.isArray(ps.userId) ? relations : relations[0]); | ||
}); |
今の実装はユーザごと、フラグごとにクエリを行っていますが、
とクエリ回数を減らせるのではないでしょうか。mongoDBだとどうなのか分かりませんが…