Skip to content

Comments

fix: 作品取得時のN+1問題を修正#248

Merged
newt239 merged 3 commits intomasterfrom
fix/event-n1
Jan 31, 2026
Merged

fix: 作品取得時のN+1問題を修正#248
newt239 merged 3 commits intomasterfrom
fix/event-n1

Conversation

@newt239
Copy link
Member

@newt239 newt239 commented Jan 25, 2026

close #235

Summary

  • 作品一覧・詳細取得時に発生していたN+1クエリ問題を修正
  • 個別クエリ(著者、タグ、ファイル)をJOINによる一括取得に変更

Test plan

  • GET /work/work で作品一覧が正常に取得できること
  • GET /work/work/{workId} で作品詳細が正常に取得できること
  • GET /user/{userId}/work でユーザーの作品一覧が正常に取得できること

newt239 and others added 2 commits January 10, 2026 14:37
- WorkUpdatedAt フィールドを削除(ORDER BYのみで使用、API応答には不要)
- aggregateWorkListRows → mapRowsToWorkList に名称変更
- aggregateWorkDetailRows → mapRowsToWorkDetail に名称変更

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 25, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
spec-core a6cd157 Commit Preview URL

Branch Preview URL
Jan 25 2026, 08:26 AM

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

このPRは、作品取得時に発生していたN+1クエリ問題を修正し、個別クエリを結合クエリに置き換えることでパフォーマンスを改善します。

Changes:

  • 作品一覧・詳細取得時の著者、タグ、ファイル情報を個別クエリからJOINベースの一括取得に変更
  • 不要なヘルパー関数(getWorkWorkTagListgetWorkWorkFileList)と対応するSQLファイルを削除
  • 結合結果を集約する新しいマッピング関数(mapRowsToWorkListmapRowsToWorkDetail)を追加

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/work/get_work_work_work_id.go 作品詳細取得をJOINベースのクエリに変更し、結果を集約するmapRowsToWorkDetail関数を追加
pkg/work/get_work_work.go 作品一覧取得をJOINベースのクエリに変更し、結果を集約するmapRowsToWorkList関数を追加
pkg/work/get_user_user_id_work.go ユーザー作品一覧取得で新しい共通クエリと集約関数を使用するように変更
pkg/db/sql/work/select_work_with_relations.sql 作品、著者、タグを一度に取得する新しいSQLクエリを追加
pkg/db/sql/work/select_work_from_work_id_with_relations.sql 作品詳細、著者、タグ、ファイルを一度に取得する新しいSQLクエリを追加
pkg/db/sql/work/select_work_work_tag.sql 不要になったタグ個別取得クエリを削除
pkg/db/sql/work/select_work_work_file.sql 不要になったファイル個別取得クエリを削除
pkg/db/sql/work/select_work_from_work_id.sql 不要になった作品基本情報取得クエリを削除
pkg/db/sql/work/select_work.sql 不要になった作品一覧取得クエリを削除

@newt239 newt239 requested a review from saka-naname January 25, 2026 08:26
Copy link
Contributor

@saka-naname saka-naname left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow

@newt239 newt239 merged commit e3530e1 into master Jan 31, 2026
3 checks passed
@newt239 newt239 deleted the fix/event-n1 branch January 31, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

作品取得におけるN+1問題の解消

2 participants