feat: Implement fuzzy username search using Elasticsearch#10876
feat: Implement fuzzy username search using Elasticsearch#10876Appleple47 wants to merge 17 commits intofeat/179909-username-fuzzy-searchfrom
Conversation
57f3b51 to
42ab20a
Compare
01922a7 to
e3de2a0
Compare
e3de2a0 to
78cc663
Compare
There was a problem hiding this comment.
API route は activiry ディレクトリ側にあるはずだからそっちに定義した方が良さそうです
| loginRequiredStrictly, | ||
| adminRequired, | ||
| async (req: Request, res: ApiV3Response) => { | ||
| const { q = '', offset = 0, limit = 5 } = req.query; |
There was a problem hiding this comment.
- express-validator による validation をしてください
- 他の API の実装も参考に
req.queryから取り出した値に型がつくようにしてください
| (result.aggregations?.unique_usernames as any)?.buckets ?? []; | ||
| const usernames = buckets.map((bucket) => bucket.key as string); |
There was a problem hiding this comment.
ここら辺 type safe にできませんか? TS の恩恵がなくなるので as any はなるべく避けたいです。
|
|
||
| const body = activities.flatMap((activity) => { | ||
| const username = activity.snapshot?.username; | ||
| if (!username) return []; |
There was a problem hiding this comment.
username != null で判定しましょう
https://tips.weseek.co.jp/5fb74e7aa1ba4200489a4bd1#%E5%88%A4%E5%AE%9A%E5%BC%8F
| const indexName = 'auditlogs'; | ||
| const tmpIndexName = 'auditlogs-tmp'; | ||
| const aliasName = 'auditlogs-alias'; |
There was a problem hiding this comment.
別のメソッドでも使い回す系のて定数はインスタンス変数とかに定義しておいた方が良さそう
| <span className="input-group-text"> | ||
| <span className="material-symbols-outlined">person</span> | ||
| </span> | ||
| <AsyncTypeahead |
There was a problem hiding this comment.
AsyncTypeahead のクライアント側フィルタリングがfuzzy検索の結果を除外していると勘違いして Typeahead に変更しましたが、filterBy={() => true} を追加すれば AsyncTypeahead のままでも動くことが発覚したので元に戻しました。
…ification and review fixes
| const q = req.query.q != null ? (req.query.q as string) : ''; | ||
| const offset = | ||
| req.query.offset != null ? parseInt(req.query.offset as string, 10) : 0; | ||
| const limit = | ||
| req.query.limit != null ? parseInt(req.query.limit as string, 10) : 5; |
There was a problem hiding this comment.
Request を extends した型を使ってみてください。assertion もなるべく使いたくないです。
参考
growi/packages/remark-lsx/src/server/routes/list-pages/index.ts
Lines 64 to 67 in 1a565b3
There was a problem hiding this comment.
// biome-ignore lint/suspicious/noTsIgnore: Suppress auto fix by lefthook
// @ts-ignore - Scope type causes "Type instantiation is excessively deep" with tsgo
get-recent-threads.ts では上のコメントをつけて運用しているみたい
| limit, | ||
| ); | ||
|
|
||
| const User = mongoose.model('User'); |
There was a problem hiding this comment.
こんな感じに書くと型がつけられるのでやってみてください
参考
| query('offset').optional().isInt().withMessage('offset must be a number'), | ||
| query('limit') | ||
| .optional() | ||
| .isInt({ max: 100 }) | ||
| .withMessage('limit must be a number less than or equal to 100'), | ||
| ], |
There was a problem hiding this comment.
.toInt()をつければreq.query.{hoge}で取り出した時に数値に変換された状態で受け取れる- parseInt が不要になる
| const q = req.query.q != null ? (req.query.q as string) : ''; | ||
| const offset = | ||
| req.query.offset != null ? parseInt(req.query.offset as string, 10) : 0; | ||
| const limit = | ||
| req.query.limit != null ? parseInt(req.query.limit as string, 10) : 5; |
There was a problem hiding this comment.
// biome-ignore lint/suspicious/noTsIgnore: Suppress auto fix by lefthook
// @ts-ignore - Scope type causes "Type instantiation is excessively deep" with tsgo
get-recent-threads.ts では上のコメントをつけて運用しているみたい
Merge Queue Status
This pull request spent 1 minute 3 seconds in the queue, with no time running CI. Required conditions to merge
ReasonThe pull request #10876 has been manually updated HintIf you want to requeue this pull request, you can post a |
Merge Queue Status
This pull request spent 4 minutes 57 seconds in the queue, including 4 minutes 39 seconds running CI. Required conditions to merge
ReasonThe merge conditions cannot be satisfied due to failing checks Failing checks: HintYou may have to fix your CI before adding the pull request to the queue again. |
Merge Queue Status
This pull request spent 4 minutes 46 seconds in the queue, including 4 minutes 36 seconds running CI. Required conditions to merge
ReasonThe merge conditions cannot be satisfied due to failing checks Failing checks: HintYou may have to fix your CI before adding the pull request to the queue again. |
|
@Appleple47 そのため、今のままではMongoDB の TTL によって古いドキュメントが削除された場合に、対応する ES 側のドキュメントが削除されないという問題がある ES 側にも ILM (Index Lifecycle Management) を設定する必要があるのではないか? MongoDB v8.2 も一応選択肢ではあるが、現時点では ES による実装の方針は正しいと思う |
| ); | ||
|
|
||
| router.get( | ||
| '/usernames', |
There was a problem hiding this comment.
Slack で相談を受けている UI 案を見ると、username だけのエンドポイントを作るのは全体設計に対してずれがあるんじゃないか?
あと REST API の設計として GET /api/v3/activity/usernames というエンドポイントから検索する挙動は想像できない
エンドポイントURLを工夫してほしい
…048-implement-fuzzy-auditlog-search
…048-implement-fuzzy-auditlog-search
…048-implement-fuzzy-auditlog-search
…048-implement-fuzzy-auditlog-search
タスク
https://redmine.weseek.co.jp/issues/180046
https://redmine.weseek.co.jp/issues/180047
https://redmine.weseek.co.jp/issues/180048