Skip to content

Conversation

@itschetna
Copy link
Contributor

@itschetna itschetna commented Jul 30, 2025

Related Issue

Description

Optimized the data fetching logic in useGitHubData.ts to reduce loading time and improve responsiveness. Previously, fetching was slower due to sequential or redundant API calls. This update ensures PRs and Issues are fetched more efficiently, reducing the wait time to just 1–2 seconds.

How Has This Been Tested?

  • Tested locally by cloning the repository and running both frontend and backend.
  • Verified the load time for PRs/issues with a sample user using real-time testing.
  • Confirmed the changes work with both fresh and cached data.
  • No console errors or API failures observed.

Screenshots (if applicable)

Screen.Recording.2025-07-30.111944.mp4

Type of Change

  • New feature
  • Breaking change

Summary by CodeRabbit

  • New Features

    • Enhanced pagination for issues and pull requests, allowing users to navigate through data pages more efficiently.
    • Display of total counts for issues and pull requests is now available for better overview.
  • Bug Fixes

    • Improved accuracy of pagination and filtering, ensuring displayed data matches selected filters and page.
  • Style

    • Updated layout and input styling for a cleaner and more consistent user interface.

@netlify
Copy link

netlify bot commented Jul 30, 2025

βœ… Deploy Preview for github-spy ready!

Name Link
πŸ”¨ Latest commit 640e3b2
πŸ” Latest deploy log https://app.netlify.com/projects/github-spy/deploys/688a0933bbc53e0008c27a36
😎 Deploy Preview https://deploy-preview-149--github-spy.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 30, 2025

Walkthrough

Pagination and data fetching logic for GitHub issues and pull requests were refactored. The usePagination hook was removed, and pagination is now managed within the Home component. The useGitHubData hook was updated to fetch a single page of data per request and provide total counts. UI and state management in Home.tsx were adjusted to align with these changes.

Changes

Cohort / File(s) Change Summary
GitHub Data Hook Refactor
src/hooks/useGitHubData.ts
Added TypeScript typing for octokit, introduced totalIssues and totalPrs state, refactored pagination logic to fetch a single page per call, renamed and restructured internal helper, updated fetchData signature and logic, and improved error typing.
Pagination Hook Removal
src/hooks/usePagination.ts
Deleted the usePagination hook, removing custom pagination logic from the codebase.
Home Component Pagination/UI Refactor
src/pages/Home/Home.tsx
Removed usage of usePagination, implemented internal page state, added effect to fetch data on page/tab/username changes, updated filtering and pagination logic, adjusted UI for new pagination flow, and standardized table rendering and controls.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HomeComponent
    participant useGitHubData
    participant GitHubAPI

    User->>HomeComponent: Submit username / change page / change tab
    HomeComponent->>useGitHubData: fetchData(username, page, perPage)
    useGitHubData->>GitHubAPI: Fetch issues (paginated)
    useGitHubData->>GitHubAPI: Fetch PRs (paginated)
    GitHubAPI-->>useGitHubData: Return items + total counts
    useGitHubData-->>HomeComponent: Update issues, PRs, total counts
    HomeComponent-->>User: Render updated table and pagination
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Optimize search result timing by reducing data fetch duration (#37) βœ…

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Poem

A hop and a skip through the code we go,
Pagination’s streamlined, fetches now flow!
No more waiting for data to appear,
Results are much fasterβ€”let’s all cheer!
The bunny approves, with a wiggle and grin,
For swift GitHub searches, let’s dig right in!
πŸ‡βœ¨

Note

⚑️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


πŸ“œ Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 94debb3 and 640e3b2.

πŸ“’ Files selected for processing (1)
  • src/pages/Home/Home.tsx (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pages/Home/Home.tsx
✨ Finishing Touches
  • πŸ“ Generate Docstrings
πŸ§ͺ Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/hooks/useGitHubData.ts (3)

9-29: LGTM with minor suggestions for improvement.

The refactored pagination logic is cleaner and more robust. The safe array check and explicit per_page: 100 parameter are good improvements.

However, the comment on line 9 is misleading since this function is actually used with the GitHub Search API (GET /search/issues), not REST endpoints.

Consider updating the comment for accuracy:

-  // Helper to fetch multiple pages from REST endpoint (not search API)
+  // Helper to fetch multiple pages from GitHub Search API with pagination

Also consider adding error handling within the pagination loop to make it more resilient to individual page failures.


38-39: Consider production-ready logging approach.

The console timing is useful for measuring the optimization impact during development.

For production code, consider using a proper logging library or removing console statements:

-      console.time('fetchData');
+      // TODO: Replace with proper logging in production
+      console.time('fetchData');

53-56: LGTM!

State updates are handled correctly, and the console timing provides useful performance metrics.

Same suggestion as earlier regarding production-ready logging for the console.timeEnd call.

πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 78e7fbb and 235124b.

πŸ“’ Files selected for processing (1)
  • src/hooks/useGitHubData.ts (3 hunks)
πŸ”‡ Additional comments (2)
src/hooks/useGitHubData.ts (2)

40-51: Excellent optimization! This addresses the core PR objective.

The Promise.all implementation enables concurrent fetching of issues and PRs, which should significantly reduce loading times as intended. The query parameters are correctly structured for both searches.


58-58: Good improvement to error handling.

The fallback error message ensures users always receive meaningful feedback, even when err.message is falsy.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/pages/Home/Home.tsx (1)

183-228: Consider pagination count consistency with filtering.

The table implementation is solid, but there's a potential UX inconsistency: the pagination uses totalCount from the API (total unfiltered results) while the table shows currentFilteredData (filtered results). This means if a user applies filters, the pagination count won't match the visible data count.

Consider whether pagination should reflect filtered data count or API total count based on your UX requirements.

Otherwise, the implementation is excellent:

  • Proper loading state handling
  • Clean table structure with appropriate data display
  • Correct pagination configuration
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 235124b and 94debb3.

πŸ“’ Files selected for processing (4)
  • src/hooks/useGitHubAuth.ts (1 hunks)
  • src/hooks/useGitHubData.ts (1 hunks)
  • src/hooks/usePagination.ts (0 hunks)
  • src/pages/Home/Home.tsx (3 hunks)
πŸ’€ Files with no reviewable changes (1)
  • src/hooks/usePagination.ts
βœ… Files skipped from review due to trivial changes (1)
  • src/hooks/useGitHubAuth.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/hooks/useGitHubData.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/pages/Home/Home.tsx (2)
src/hooks/useGitHubAuth.ts (1)
  • useGitHubAuth (4-23)
src/hooks/useGitHubData.ts (1)
  • useGitHubData (3-65)
πŸ”‡ Additional comments (7)
src/pages/Home/Home.tsx (7)

1-1: LGTM: Added necessary import for new useEffect usage.

The addition of useEffect import is required for the new pagination effect implementation.


41-43: LGTM: Hook integration updated correctly.

The destructuring of both hooks is updated to include the new state variables (totalIssues, totalPrs) from the optimized useGitHubData hook.


46-53: LGTM: Filter state management looks good.

The addition of pagination and filter state variables provides good separation of concerns and follows React best practices.


62-70: LGTM: Event handlers updated correctly.

Good implementation:

  • Resetting page to 0 on new search prevents pagination issues
  • Proper conversion between 0-based UI pagination and 1-based API pagination
  • Clean and straightforward page change handler

72-115: LGTM: Excellent consolidation of filtering logic.

The new filterData function provides several improvements:

  • Centralizes all filtering logic for better maintainability
  • Handles all filter types correctly (state, title, repository, date range)
  • Properly handles the "merged" state for pull requests
  • Uses immutable filtering patterns with spread operator
  • Clear data flow with currentRawData and currentFilteredData

149-175: LGTM: Great UI/UX improvements.

Excellent reorganization of the interface:

  • Filters are logically grouped with responsive flex layout
  • Tabs display total counts for better user awareness
  • Side-by-side tabs and state filter with responsive wrapping
  • Page reset on tab change prevents pagination errors
  • Clean, modern layout with appropriate spacing

40-231: Excellent implementation aligning with optimization objectives.

This refactor successfully achieves the PR goals:

βœ… Performance: Leverages the optimized useGitHubData hook with Promise.all for concurrent API calls
βœ… Pagination: Implements efficient API-level pagination instead of fetching all data
βœ… State Management: Clean internal state management replacing the deleted usePagination hook
βœ… UX: Improved layout, total counts in tabs, and responsive design
βœ… Maintainability: Consolidated filtering logic and clear data flow

The component is well-structured and should deliver the promised 1-2 second loading time improvement.

@mehul-m-prajapati mehul-m-prajapati merged commit a0455dc into GitMetricsLab:main Jul 30, 2025
6 checks passed
@github-actions
Copy link

πŸŽ‰πŸŽ‰ Thank you for your contribution! Your PR #149 has been merged! πŸŽ‰πŸŽ‰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

πŸš€ Feature: Optimize search result timing when user clicks on Fetch Data

2 participants