Skip to content

feat(web): 分野詳細に「この分野を設定している項目」逆参照を追加#11

Merged
kentalow merged 4 commits into
mainfrom
feat/subject-reverse-items
Jun 20, 2026
Merged

feat(web): 分野詳細に「この分野を設定している項目」逆参照を追加#11
kentalow merged 4 commits into
mainfrom
feat/subject-reverse-items

Conversation

@kentalow

Copy link
Copy Markdown
Member

概要

CFSubject(分野)詳細ページに、同一テナント内でこの分野を subjectURI で参照している CFItem の一覧を表示します(CFItem→CFSubject の逆引き)。上位20件を SSR、件数表示、「もっと見る」で次ページを HTMX で自己再帰的に追記(案A:別ページに飛ばさない)。

旧 PR #10 の作り直し。base を GIN 索引ブランチにしていたが、そのブランチ(#9)が main にマージ&削除され #10 が自動クローズされたため、main を取り込んだ本ブランチで base=main の新規 PR として再作成。GIN 索引(#9)は main 済みなので本 PR の差分は機能のみ。Codex レビュー(P2 修正含む)反映済み。

実装

  • repository cf_item_repository: list_items_by_subject / count_items_by_subjectsubject_uri @> '[{"identifier": ...}]' 包含クエリ(GIN索引 ix_cf_items_subject_uri_gin を使用=EXPLAIN で Bitmap Index Scan 確認済み)、テナントスコープ、安定ソート、offset ページング。
  • router/service web.py: _detail_extrasCFSubject 分岐(include_subject_items 引数で右ペインでは計算・表示を抑止)、subject_items_DETAIL_EXTRAS_KEYSpane_extras 両方に追加、GET /{tenant}/subject/{id}/items フラグメントルート(CFSubject 検証・limit+1 で has_more・Cache-Control: 86400)。
  • template: 再利用フラグメント fragments/subject_items.html(SSR include と HTMX 両用)、resource_detail.html の lookup 分岐に CFSubject ゲートで挿入。
  • i18n: subject_items_label / subject_items_count / show_more(en/ja)。

スコープ

  • テナント内のみsubjectURI 参照のみ(subject 文字列のみは対象外)、subject のみ、ツリー右ペインでは非表示(ドキュメントスコープ・Codex P2 対応)。

テスト(計15件 / 全692 pass)

  • repo: 包含一致・除外、テナントスコープ、ページング境界、count、空。
  • Web: 分野ページ(上位N+件数+ボタン/1ページ内はボタン無し/空は非表示)、フラグメント(次ページ+自己再帰/最終ページはボタン無し)、検証(非CFSubject→404・bad UUID→400・未知→404)、Cache-Control。
  • 回帰: _detail_extrasinclude_subject_items 挙動 / ペインフラグメントで非表示。

ドキュメント

  • docs/spec/web-ui.md: 分野逆参照節・フラグメントルート。

デモ実データ用の subjectURI 付与は別途対応。

🤖 Generated with Claude Code

kentalow and others added 4 commits June 20, 2026 17:19
分野の逆引き(この分野を設定している項目)で使う JSONB 包含クエリ
subject_uri @> '[{"identifier": ...}]' を高速化する GIN(jsonb_path_ops)
索引を追加。大規模フレームワークでも seq scan を避ける。

- migration d1a2b3c4e5f6(down_revision c704faa62b4f)
- cf_item.py の __table_args__ に同索引をミラー(autogenerate 整合)
- db-schema.md(英/日)の cf_item 索引一覧に追記

逆引き機能(router/template)は後続 PR。索引のみ先行。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XXFogp18twGiPFBAZcqJw2
CFSubject 詳細ページ(/uri/{subject})に、同一テナント内でこの分野を
subjectURI で参照している CFItem の一覧を表示する。上位20件をSSR、件数表示、
「もっと見る」で HTMX フラグメント(/{tenant}/subject/{id}/items)から次ページを
自己再帰的に追記(ツリーの遅延ロードと同作法)。

- cf_item_repository: list_items_by_subject / count_items_by_subject
  (subject_uri @> 包含・GIN索引利用・テナントスコープ・安定ソート・ページング)
- web.py: _detail_extras に CFSubject 分岐、subject_items を _DETAIL_EXTRAS_KEYS
  と pane_extras 両方に追加、subject_items_fragment ルート(CFSubject 検証・
  limit+1 で has_more 判定・Cache-Control フラグメント)
- 再利用フラグメント fragments/subject_items.html(SSR include と HTMX 両用)、
  resource_detail.html の lookup 分岐に CFSubject ゲートで挿入
- i18n: subject_items_label / subject_items_count / show_more
- tests: unit(包含/テナントスコープ/ページング/count/空)+ integration
  (分野ページ/フラグメント/検証404・400/cache/空状態)計13件
- docs: web-ui.md(分野逆参照節・フラグメントルート)

テナント内のみ(分野はテナント所有)。subject 文字列のみの参照は対象外。
GIN索引は先行PR、デモデータ(subjectURI付与)は別途対応。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XXFogp18twGiPFBAZcqJw2
CFSubject をツリーの Definitions からクリックして右ペインに開いたとき、
_pane_fragment_response が _detail_extras を普通に呼ぶため「この分野を設定して
いる項目」が出てしまっていた(初期SSRの pane_extras では空にしていたが、HTMX
ペイン更新経路が漏れていた)。

_detail_extras に include_subject_items 引数を追加し、ペイン経路(in_pane)では
False を渡して計算自体を抑止(テンプレ条件だけでなくクエリも走らせない)。
単独 /uri/ ページのみ表示する。

- 回帰テスト2件追加(_detail_extras のフラグ挙動 / ペインフラグメントで非表示)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XXFogp18twGiPFBAZcqJw2
@kentalow kentalow merged commit 221d5e4 into main Jun 20, 2026
2 checks passed
@kentalow kentalow deleted the feat/subject-reverse-items branch June 20, 2026 10:34
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.

1 participant