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

* 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 <9099342+JonnyWong16@users.noreply.github.com>

---------

Co-authored-by: Graham Thompson <graham.c.thompson@gmail.com>
Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>
This commit is contained in:
Touchstone64 2024-04-19 18:57:54 +01:00 committed by GitHub
parent bf925c60e1
commit 3e752d5f27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 5 deletions

View file

@ -283,6 +283,11 @@ class PlexObject:
results.extend(subresults) results.extend(subresults)
container_start += container_size
if container_start > total_size:
break
wanted_number_of_items = total_size - offset wanted_number_of_items = total_size - offset
if maxresults is not None: if maxresults is not None:
wanted_number_of_items = min(maxresults, wanted_number_of_items) wanted_number_of_items = min(maxresults, wanted_number_of_items)
@ -291,11 +296,6 @@ class PlexObject:
if wanted_number_of_items <= len(results): if wanted_number_of_items <= len(results):
break break
container_start += container_size
if container_start > total_size:
break
return results return results
def fetchItem(self, ekey, cls=None, **kwargs): def fetchItem(self, ekey, cls=None, **kwargs):

View file

@ -120,6 +120,16 @@ def test_library_fetchItem(plex, movie):
assert item1 == item2 == 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): def test_library_onDeck(plex, movie):
movie.updateProgress(movie.duration // 4) # set progress to 25% movie.updateProgress(movie.duration // 4) # set progress to 25%
assert movie in plex.library.onDeck() assert movie in plex.library.onDeck()