Skip to content

feat: add paginated category retrieval using static taxonomy (#106)#463

Closed
piyush247-gif wants to merge 2 commits intoopenfoodfacts:developfrom
piyush247-gif:feat/category-pagination
Closed

feat: add paginated category retrieval using static taxonomy (#106)#463
piyush247-gif wants to merge 2 commits intoopenfoodfacts:developfrom
piyush247-gif:feat/category-pagination

Conversation

@piyush247-gif
Copy link
Copy Markdown

Overview
This PR addresses Issue #106. The previous implementation for category retrieval was hitting the live API, which frequently returns 503 Service Unavailable errors due to the heavy load of the taxonomy.

Changes

Implemented get_categories within FacetResource using the high-performance static taxonomy (get_taxonomy("category")).

Added support for pagination (page and page_size) to allow efficient data fetching without overloading the client.

Verified the fix locally using the project's source code; it successfully retrieves categories (e.g., "Beef", "Asenovgrad") without server timeouts.

Testing
Confirmed functionality with a standalone test script by forcing PYTHONPATH=src to ensure the local changes were active.

@sonarqubecloud
Copy link
Copy Markdown

@piyush247-gif
Copy link
Copy Markdown
Author

Hi team, I have pushed a dedicated unit test (tests/unit/test_facets.py) that uses mocked taxonomy nodes to verify the pagination logic. This resolves the missing test coverage highlighted by SonarQube. All checks are passing locally on my end. Please let me know if this looks good to merge, or if you need any final adjustments!

Comment thread src/openfoodfacts/api.py
params={"json": "1", "page": page, "page_size": page_size, **kwargs},
api_config=self.api_config,
method="GET",
api_config=self.api_config, # <--- Make sure these line up
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hi @piyush247-gif, i noticed this pr seems to heavily reflect ai usage and i’m not sure if that’s the best approach. also, there’s another pr from a different contributor addressing the same issue.

for future prs, please make sure to discuss the approach in the slack channel (#api or #product-opener) first before raising the pr. this will help ensure we’re all aligned and make the process more effective.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants