feat: add paginated category retrieval using static taxonomy (#106)#463
feat: add paginated category retrieval using static taxonomy (#106)#463piyush247-gif wants to merge 2 commits intoopenfoodfacts:developfrom
Conversation
|
|
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! |
| 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 |
There was a problem hiding this comment.
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.



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.