Skip to content

お気に入り一覧の取得を最適化#19

Merged
MurakawaTakuya merged 3 commits intomainfrom
optimize-fetching-favorite-list
Feb 15, 2026
Merged

お気に入り一覧の取得を最適化#19
MurakawaTakuya merged 3 commits intomainfrom
optimize-fetching-favorite-list

Conversation

@MurakawaTakuya
Copy link
Owner

No description provided.

@MurakawaTakuya MurakawaTakuya self-assigned this Feb 15, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @MurakawaTakuya, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

このプルリクエストは、お気に入りアイテムの取得を最適化し、軽量なデータ取得のための新しいAPIエンドポイントパラメータを導入し、お気に入り管理ロジックをReact Contextにリファクタリングします。これにより、特にどの論文がお気に入り登録されているかだけを知る必要があるコンポーネントのパフォーマンスが向上し、完全なデータ取得をクライアントに移動し、楽観的UI更新を実装することで、お気に入りページの応答性が強化されます。

Highlights

  • お気に入りAPIの最適化: /api/favoritesエンドポイントにidsOnlyクエリパラメータが追加されました。これにより、お気に入りのID、論文ID、フォルダIDのみを軽量に取得できるようになり、必要なデータ量が削減されます。
  • お気に入り管理ロジックのContext化: useFavoritesフックがFavoritesContextFavoritesProviderにリファクタリングされました。これにより、お気に入り管理ロジックが一元化され、コンポーネントがお気に入りの変更に効率的にサブスクライブできるようになります。
  • お気に入りページのクライアントサイドデータ取得: src/app/favorites/page.tsxが、useEffectを使用して完全なお気に入りデータ(論文詳細を含む)をクライアントサイドで直接フェッチするようになりました。Contextは主にfavoritePaperIdsとフォルダ情報を管理します。
  • お気に入り操作の楽観的UI更新: FavoritesContext内でaddFavoriteremoveFavoriteremoveFavoriteByPaperId操作に対して楽観的UI更新が実装され、ユーザー体験の応答性が向上しました。
  • フォルダ管理の即時状態更新: フォルダの作成、名前変更、削除が、すべてのフォルダを再フェッチするのではなく、FavoritesContext内のfoldersステートを直接更新するようになり、UIの応答性が向上しました。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/app/api/favorites/route.ts
    • お気に入りのIDとフォルダIDのみをフェッチするためのidsOnlyクエリパラメータを追加しました。
    • デフォルトのお気に入り取得で論文フィールドを明示的に選択するように変更し、一貫性を確保しました。
  • src/app/favorites/page.tsx
    • useFavoritesのインポートをフックからFavoritesContextに変更しました。
    • folderIdParamに基づいてuseEffectを使用して完全なお気に入りデータをクライアントサイドでフェッチするように実装しました。
    • Contextのロードとローカルのお気に入りフェッチを考慮して、ロード状態ロジックを更新しました。
    • APIがフィルタリングを処理するため、クライアントサイドのお気に入りフィルタリングを削除しました。
  • src/app/layout.tsx
    • SearchHistoryProviderSidebarProviderFavoritesProviderでラップし、Contextをグローバルに利用できるようにしました。
  • src/components/app-sidebar.tsx
    • useFavoritesのインポートを新しいContextを使用するように更新しました。
  • src/components/categorization-results.tsx
    • useFavoritesのインポートを新しいContextを使用するように更新しました。
  • src/components/papers-table.tsx
    • useFavoritesのインポートを新しいContextを使用するように更新しました。
    • 完全なデータが直接公開されなくなったため、useFavoritesの分割代入からfavoritesを削除しました。
  • src/hooks/use-favorites.ts
    • ファイルがsrc/contexts/FavoritesContext.tsxにリネームされました。
    • useFavoritesフックがFavoritesContextFavoritesProviderにリファクタリングされました。
    • 軽量なお気に入りデータのためのFavoriteIdItemインターフェースを導入しました。
    • fetchFoldersfetchFavoritesIds(軽量データ用)を分離しました。
    • addFavoriteremoveFavoriteremoveFavoriteByPaperIdに対して楽観的更新を実装しました。
    • createFolderrenameFolderdeleteFolderがフォルダのローカル状態を直接変更するように更新しました。
    • トーストメッセージのためにremoveFavoritepaperIdを受け入れるように変更しました。
    • 一括追加後、addGroupToFolderfavoriteItemsのみを更新するように調整しました。
    • 一括追加が失敗した場合のaddGroupToFolderのロールバックロジックを追加しました。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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

お気に入り一覧の取得負荷を下げるため、全件の論文データ取得をやめて「お気に入りID+フォルダ紐付け」の軽量データを Context で保持し、必要な画面のみ全文データを取得する構成に変更するPRです。

Changes:

  • FavoritesContext を新設/刷新し、/api/favorites?idsOnly=true で軽量データを取得するよう変更
  • /api/favoritesidsOnly クエリを追加し、軽量レスポンスを返す分岐を実装
  • 主要コンポーネントの useFavorites 参照元を hooks から context に移行し、RootLayout に Provider を追加

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/contexts/FavoritesContext.tsx お気に入りの軽量状態管理(ID/フォルダ紐付け)とCRUD操作を Context として提供
src/app/api/favorites/route.ts GET に idsOnly 分岐を追加し、軽量な favorites レコードのみ返せるように変更
src/app/layout.tsx 画面全体で favorites 状態を使えるよう FavoritesProvider を追加
src/app/favorites/page.tsx お気に入りページはローカルで「全文 favorites」を取得する方式に変更
src/components/papers-table.tsx useFavorites の import を contexts に切替、Context のヘルパー利用に整理
src/components/categorization-results.tsx useFavorites の import を contexts に切替
src/components/app-sidebar.tsx useFavorites の import を contexts に切替
Comments suppressed due to low confidence (5)

src/app/favorites/page.tsx:241

  • This page fetches full favorites into local state once, but the table’s favorite actions (via FavoriteButton -> context toggleFolder / removeFavoriteByPaperId) won’t update this local favorites list. As a result, removing a favorite from this page can leave the paper row visible until a manual refresh/navigation. Consider re-fetching after successful mutations (e.g., pass a callback into PapersTable/FavoriteButton, or refetch when the context favorites state changes).
      <div className="flex flex-col items-center gap-8 w-full max-w-7xl px-4 mx-auto pb-24">
        {favoritesLoading ? (
          <div className="flex justify-center py-12">
            <Spinner className="h-8 w-8" />
          </div>
        ) : papers.length > 0 ? (
          <PapersTable
            papers={papers}
            selectedPapers={new Set()}
            message=""
            readOnly={false}
            showSimilarity={false}
          />

src/contexts/FavoritesContext.tsx:64

  • favoritePaperIds is recreated as a new Set on every render. This makes the reference unstable and can trigger unnecessary re-renders / effects in consumers even when the underlying IDs haven’t changed. Consider memoizing it (e.g., with useMemo keyed by favoriteItems) and/or memoizing the provider value object.
    src/contexts/FavoritesContext.tsx:109
  • The mounted flag only guards setLoading(false), but fetchFolders / fetchFavoritesIds can still call setFolders/setFavoriteItems after unmount, which defeats the intent and can lead to “state update on unmounted component” warnings. Consider wiring an AbortController into the fetches or passing a cancellation flag into fetchFolders/fetchFavoritesIds and skipping all state updates when unmounted.
    src/contexts/FavoritesContext.tsx:200
  • removeFavorite accepts paperId but doesn’t use it anywhere. If ESLint’s unused-vars rule is enabled this will fail CI; even if not, it’s confusing API surface. Either remove the parameter, rename it to _paperId to indicate intentional unused, or actually use it for the toast lookup as the comment suggests.
    src/contexts/FavoritesContext.tsx:411
  • Rollback on batch-add failure calls deleteFolder(newFolder.id), which will emit a success/error toast and also triggers fetchFavoritesIds(). That can confuse users (they’ll see a “folder deleted” toast even though they never explicitly deleted it). Consider adding a “silent” delete path (no toast/no extra refresh) for rollback, or letting deleteFolder accept an option to suppress notifications.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、お気に入り機能のデータ取得方法を最適化するための重要なリファクタリングであり、カスタムフックuse-favoritesをReact Context FavoritesContextに移行し、グローバルな状態管理を軽量なIDベースのデータで行うことで、アプリケーション全体のパフォーマンス向上と関心事の分離を促進しています。セキュリティ面では、特定の脆弱性や重大な問題は見つかりませんでした。いくつかの改善点を提案しましたが、全体として非常によく考えられた変更だと思います。

@MurakawaTakuya MurakawaTakuya merged commit d06c180 into main Feb 15, 2026
1 check passed
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.

2 participants