-
Notifications
You must be signed in to change notification settings - Fork 0
feat: batch fetch Plex items #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: batch fetch Plex items #53
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements batch fetching for Plex metadata to reduce repetitive network calls during library loading. Instead of individually fetching each item with fetchItem(), the code now collects all rating keys and retrieves items in bulk using fetchItems().
- Replaces individual
fetchItem()calls with batchfetchItems()operations - Updates test mocks to simulate the new batch fetching behavior
- Documents the batch fetching approach in the AGENTS guidelines
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| mcp_plex/loader.py | Implements batch fetching using fetchItems() for movies, shows, and episodes |
| tests/test_load_from_plex.py | Updates test mocks to support batch fetching and removes individual fetchItem methods |
| AGENTS.md | Documents the batch fetching optimization in architecture notes |
| pyproject.toml | Version bump to 0.26.19 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| movie_keys = [int(m.ratingKey) for m in movie_section.all()] | ||
| movies = server.fetchItems(movie_keys) if movie_keys else [] | ||
| movie_tasks = [_augment_movie(client, movie) for movie in movies] | ||
| if movie_tasks: | ||
| results.extend(await _gather_in_batches(movie_tasks, batch_size)) | ||
|
|
||
| show_section = server.library.section("TV Shows") | ||
| for show in show_section.all(): | ||
| full_show = show.fetchItem(show.ratingKey) | ||
| show_keys = [int(s.ratingKey) for s in show_section.all()] | ||
| full_shows = server.fetchItems(show_keys) if show_keys else [] | ||
| for full_show in full_shows: | ||
| show_ids = _extract_external_ids(full_show) | ||
| show_tmdb: Optional[TMDBShow] = None | ||
| if show_ids.tmdb: | ||
| show_tmdb = await _fetch_tmdb_show(client, show_ids.tmdb, tmdb_api_key) | ||
| episode_keys = [int(e.ratingKey) for e in full_show.episodes()] |
Copilot
AI
Sep 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fetchItems method expects string keys based on the test implementation, but this code converts them to integers. This type mismatch could cause runtime errors when calling the Plex API.
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||
What
fetchItemsWhy
Affects
loader._load_from_plexTesting
uv run ruff check .uv run pytestDocumentation
AGENTS.mdhttps://chatgpt.com/codex/tasks/task_e_68c665c8cef0832895b1ccc7a9e8fe3b