perf(news): use direct API endpoint for get_item()

Replace O(n) fetch-all-and-filter approach with O(1) direct API call.
The News API v1-3 supports GET /items/{id} for single-item retrieval.

- Update get_item() to use direct endpoint
- Add unit test for get_item() method
- Fixes critical performance issue identified in code review

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2025-11-29 17:22:51 +01:00
parent 0bedbf1877
commit 92c4bf36f6
2 changed files with 22 additions and 12 deletions
+3 -12
View File
@@ -228,10 +228,6 @@ class NewsClient(BaseNextcloudClient):
async def get_item(self, item_id: int) -> dict[str, Any]:
"""Get a specific item by ID.
Note: The News API doesn't have a direct single-item endpoint,
so we fetch all items and filter. For efficiency, consider
caching or using get_items with specific feed if known.
Args:
item_id: Item ID
@@ -239,15 +235,10 @@ class NewsClient(BaseNextcloudClient):
Item data
Raises:
ValueError: If item not found
HTTPStatusError: 404 if item not found
"""
# Fetch all items and find the one we need
# This is inefficient but the API doesn't provide a direct endpoint
items = await self.get_items(batch_size=-1, get_read=True)
for item in items:
if item.get("id") == item_id:
return item
raise ValueError(f"Item {item_id} not found")
response = await self._make_request("GET", f"{self.API_BASE}/items/{item_id}")
return response.json()
async def get_updated_items(
self,