Skip to content
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

Fix: stop maxresults from overwriting previous results #1393 #1394

Merged
merged 7 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions plexapi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,

results.extend(subresults)

container_start += container_size

if container_start > total_size:
break

wanted_number_of_items = total_size - offset
if maxresults is not None:
wanted_number_of_items = min(maxresults, wanted_number_of_items)
Expand All @@ -291,11 +296,6 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
if wanted_number_of_items <= len(results):
break

container_start += container_size

if container_start > total_size:
break

return results

def fetchItem(self, ekey, cls=None, **kwargs):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ def test_library_fetchItem(plex, movie):
assert item1 == item2 == movie


def test_library_fetchItems_with_maxresults(plex, tvshows):
items = tvshows.searchEpisodes()
assert len(items) > 5
size = len(items) - 5
ratingKeys = [item.ratingKey for item in items]
items1 = plex.fetchItems(ekey=ratingKeys, container_size=size)
items2 = plex.fetchItems(ekey=ratingKeys, container_size=size, maxresults=len(items))
assert items1 == items2 == items


def test_library_onDeck(plex, movie):
movie.updateProgress(movie.duration // 4) # set progress to 25%
assert movie in plex.library.onDeck()
Expand Down