Skip to content

Commit

Permalink
Fix: stop maxresults from overwriting previous results #1393 (#1394)
Browse files Browse the repository at this point in the history
* Fix: stop maxresults from overwriting previous results

* Added test for use of maxresults in fetchItems #1393

* Removed the need for last_container_size #1393

* Renamed collections to better represen what is being tested

* Renamed collections to better represent what is being tested #1393

* Update tests/test_library.py with cleaner test

Co-authored-by: JonnyWong16 <[email protected]>

---------

Co-authored-by: Graham Thompson <[email protected]>
Co-authored-by: JonnyWong16 <[email protected]>
  • Loading branch information
3 people authored Apr 19, 2024
1 parent bf925c6 commit 3e752d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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

0 comments on commit 3e752d5

Please sign in to comment.