Skip to content

Conversation

@Teagan42
Copy link
Contributor

What

  • batch-retrieve Plex movies, shows, and episodes with fetchItems
  • document batch fetching in AGENTS guidelines

Why

  • reduce repetitive metadata lookups and network calls

Affects

  • loader._load_from_plex
  • test expectations and project docs

Testing

  • uv run ruff check .
  • uv run pytest

Documentation

  • updated AGENTS.md

https://chatgpt.com/codex/tasks/task_e_68c665c8cef0832895b1ccc7a9e8fe3b

Copilot AI review requested due to automatic review settings September 14, 2025 06:54
Copy link
Contributor

Copilot AI left a 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 batch fetchItems() 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.

Comment on lines +319 to +333
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()]
Copy link

Copilot AI Sep 14, 2025

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.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

Coverage

Coverage Report
FileStmtsMissCoverMissing
mcp_plex
   cache.py36489%22, 50–52
   imdb_cache.py20290%17–18
   loader.py3022392%33–35, 86, 99–100, 113, 120, 188, 206, 218, 220, 459–461, 471, 474–478, 603, 858
   server.py2982293%59–60, 102–103, 226, 454, 458, 480–486, 518, 528, 559–560, 577–578, 601, 604–605, 663
TOTAL7815193% 

Tests Skipped Failures Errors Time
36 0 💤 0 ❌ 0 🔥 27.887s ⏱️

@Teagan42 Teagan42 merged commit 0bfe528 into main Sep 14, 2025
4 checks passed
@Teagan42 Teagan42 deleted the codex/update-fetchitems-method-for-batch-retrieval branch September 14, 2025 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants