Skip to content

Commit

Permalink
Refactor: [Server][Routers] QuerySet の書き方を統一
Browse files Browse the repository at this point in the history
他にも統一できていない箇所はあるが、意図しないデグレが怖いので取り敢えずこの辺だけ
  • Loading branch information
tsukumijima committed Apr 15, 2024
1 parent 8a4ea59 commit c7d5342
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 7 additions & 6 deletions server/app/routers/SeriesRouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ async def SeriesListAPI(

PAGE_SIZE = 100
series_list = await Series.all() \
.prefetch_related('broadcast_periods') \
.prefetch_related('broadcast_periods__recorded_programs') \
.select_related('broadcast_periods') \
.select_related('broadcast_periods__channel') \
.select_related('broadcast_periods__recorded_programs') \
.select_related('broadcast_periods__recorded_programs__recorded_video') \
.select_related('broadcast_periods__recorded_programs__channel') \
.order_by('-updated_at' if order == 'desc' else 'updated_at') \
Expand All @@ -64,12 +64,13 @@ async def SeriesAPI(
指定されたシリーズ番組を取得する。
"""

series = await Series.get_or_none(id=series_id) \
.prefetch_related('broadcast_periods') \
.prefetch_related('broadcast_periods__recorded_programs') \
series = await Series.all() \
.select_related('broadcast_periods') \
.select_related('broadcast_periods__channel') \
.select_related('broadcast_periods__recorded_programs') \
.select_related('broadcast_periods__recorded_programs__recorded_video') \
.select_related('broadcast_periods__recorded_programs__channel')
.select_related('broadcast_periods__recorded_programs__channel') \
.get_or_none(id=series_id)
if series is None:
logging.error(f'[SeriesRouter][SeriesAPI] Specified series_id was not found [series_id: {series_id}]')
raise HTTPException(
Expand Down
10 changes: 6 additions & 4 deletions server/app/routers/VideosRouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ async def VideoAPI(
指定された録画番組を取得する。
"""

recorded_program = await RecordedProgram.get_or_none(id=video_id) \
recorded_program = await RecordedProgram.all() \
.select_related('recorded_video') \
.select_related('channel')
.select_related('channel') \
.get_or_none(id=video_id)
if recorded_program is None:
logging.error(f'[VideosRouter][VideoAPI] Specified video_id was not found [video_id: {video_id}]')
raise HTTPException(
Expand All @@ -89,9 +90,10 @@ async def VideoJikkyoCommentsAPI(
ニコニコ実況 過去ログ API をラップし、DPlayer が受け付けるコメント形式に変換して返す。
"""

recorded_program = await RecordedProgram.get_or_none(id=video_id) \
recorded_program = await RecordedProgram.all() \
.select_related('recorded_video') \
.select_related('channel')
.select_related('channel') \
.get_or_none(id=video_id)
if recorded_program is None:
logging.error(f'[VideosRouter][VideoAPI] Specified video_id was not found [video_id: {video_id}]')
raise HTTPException(
Expand Down

0 comments on commit c7d5342

Please sign in to comment.