Skip to content

Bug: Prevent empty pagination requests in feed API#3023

Open
nicktytarenko wants to merge 2 commits intomainfrom
prevent-empty-pagination-requests-in-feed-API
Open

Bug: Prevent empty pagination requests in feed API#3023
nicktytarenko wants to merge 2 commits intomainfrom
prevent-empty-pagination-requests-in-feed-API

Conversation

@nicktytarenko
Copy link
Copy Markdown
Contributor

ResearchHub/issues#684

What?

The feed API endpoint (/api/feed/) was returning a next pagination link even when there were no more items to fetch. This caused the frontend to make unnecessary API requests to empty pages.

Example:

  • Request: api/feed/?page=1&page_size=20&feed_view=popular&hub_slug=biology
  • Response: Returns 5 items but includes next pointing to page=2
  • Frontend makes another request to page=2 which returns empty results

Solution

Updated FeedPagination.get_paginated_response() to only include the next link when the number of results equals the requested page size. This ensures:

  • If you get a full page (e.g., 20 items when requesting 20), include next (more pages may exist)
  • If you get fewer items than requested (e.g., 5 items when requesting 20), omit next (no more pages)

@nicktytarenko nicktytarenko requested a review from a team as a code owner January 17, 2026 19:38
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.69%. Comparing base (cdf4b59) to head (72cf463).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3023   +/-   ##
=======================================
  Coverage   76.69%   76.69%           
=======================================
  Files         550      550           
  Lines       29508    29509    +1     
=======================================
+ Hits        22632    22633    +1     
  Misses       6876     6876           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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