Skip to content

Commit 3e752d5

Browse files
Touchstone64Graham ThompsonJonnyWong16
authored
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>
1 parent bf925c6 commit 3e752d5

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

plexapi/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
283283

284284
results.extend(subresults)
285285

286+
container_start += container_size
287+
288+
if container_start > total_size:
289+
break
290+
286291
wanted_number_of_items = total_size - offset
287292
if maxresults is not None:
288293
wanted_number_of_items = min(maxresults, wanted_number_of_items)
@@ -291,11 +296,6 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
291296
if wanted_number_of_items <= len(results):
292297
break
293298

294-
container_start += container_size
295-
296-
if container_start > total_size:
297-
break
298-
299299
return results
300300

301301
def fetchItem(self, ekey, cls=None, **kwargs):

tests/test_library.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ def test_library_fetchItem(plex, movie):
120120
assert item1 == item2 == movie
121121

122122

123+
def test_library_fetchItems_with_maxresults(plex, tvshows):
124+
items = tvshows.searchEpisodes()
125+
assert len(items) > 5
126+
size = len(items) - 5
127+
ratingKeys = [item.ratingKey for item in items]
128+
items1 = plex.fetchItems(ekey=ratingKeys, container_size=size)
129+
items2 = plex.fetchItems(ekey=ratingKeys, container_size=size, maxresults=len(items))
130+
assert items1 == items2 == items
131+
132+
123133
def test_library_onDeck(plex, movie):
124134
movie.updateProgress(movie.duration // 4) # set progress to 25%
125135
assert movie in plex.library.onDeck()

0 commit comments

Comments
 (0)