-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add search endpoint logic. #141
Conversation
api/pyproject.toml
Outdated
@@ -61,7 +61,7 @@ dev=[ | |||
"httpx", | |||
] | |||
prod=[ | |||
"birdxplorer_common @ git+https://github.com/codeforjapan/BirdXplorer.git@main#subdirectory=common", | |||
"birdxplorer_common @ git+https://github.com/codeforjapan/BirdXplorer.git@feature/138#subdirectory=common", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここはもとに戻してからマージですね。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このコメントアウトは意図通りですか?
common/birdxplorer_common/storage.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
search_notes_with_posts
と count_search_results
のフィルタを適用する部分は private 関数に切り出してまとめてもいいかもしれません。(他のところにもありますので、一気にまとめたくなるかもしれませんが、一旦これだけやる想定です)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yu23ki14
予期せぬ挙動を起こす可能性があるため、修正したほうが良さそうな部分についてコメントしました 🙏
api/birdxplorer_api/routers/data.py
Outdated
# Generate pagination URLs | ||
base_url = str(request.url).split("?")[0] | ||
next_offset = offset + limit | ||
prev_offset = max(offset - limit, 0) | ||
next_url = None | ||
if next_offset < total_count: | ||
next_url = f"{base_url}?offset={next_offset}&limit={limit}" | ||
prev_url = None | ||
if offset > 0: | ||
prev_url = f"{base_url}?offset={prev_offset}&limit={limit}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MUST] (Viewer ユーザー影響あり)
?post_includes_text=地震&offset=0&limit=4
のように limit / offset 以外が指定されたクエリの場合、
next が ?offset=4&limit=4
となってしまうので urllib.parse
を使うなどして現在のクエリをマージする実装にしないと予想外の挙動になりそうです!
api/birdxplorer_api/routers/data.py
Outdated
if note_created_at_from is not None and isinstance(note_created_at_from, str): | ||
note_created_at_from = ensure_twitter_timestamp(note_created_at_from) | ||
if note_created_at_to is not None and isinstance(note_created_at_to, str): | ||
note_created_at_to = ensure_twitter_timestamp(note_created_at_to) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MUST]
ensure_twitter_timestamp
に現在時刻より未来の値を渡すと
OverflowError: signed integer is greater than maximum
が出ていそうです。
これは入力されうる異常値なので、ハンドリングして DB クエリに 異常値を渡さないように変更したほうが良さそうです。
[imo]
ensure_twitter_timestamp
からは一般的な Error を投げて API Handler 側で HTTPException を投げ直すのが見通しが良さそうに思いました!
NoteとPostを統合的に検索する
/api/v1/data/search
を実装。変更点
BirdXplorer/api/birdxplorer_api/routers/data.py
Line 418 in e4fce05
BirdXplorer/common/birdxplorer_common/storage.py
Line 510 in e4fce05
BirdXplorer/common/birdxplorer_common/storage.py
Line 604 in e4fce05
テストコードは
./tests/test_search.py
に記述メモ