From facfd11f2fe04450ce9de209691578fd1cd1819b Mon Sep 17 00:00:00 2001 From: William McBrine Date: Sat, 5 Jan 2008 01:05:42 -0500 Subject: [PATCH] Requested AnchorItems are usually (always?) within the last set of results returned, so we can speed up the search by starting there. --- plugin.py | 12 +++++++++--- plugins/music/music.py | 6 +++++- plugins/photo/photo.py | 8 ++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/plugin.py b/plugin.py index 19d4343..725961d 100644 --- a/plugin.py +++ b/plugin.py @@ -58,7 +58,7 @@ class Plugin(object): path = os.path.join(path, folder) return path - def item_count(self, handler, query, cname, files): + def item_count(self, handler, query, cname, files, last_start=0): """Return only the desired portion of the list, as specified by ItemCount, AnchorItem and AnchorOffset. 'files' is either a list of strings, OR a list of objects with a 'name' attribute. @@ -86,9 +86,15 @@ class Plugin(object): else: filenames = [x.name for x in files] try: - index = filenames.index(anchor) + index = filenames.index(anchor, last_start) except ValueError: - print 'Anchor not found:', anchor # just use index = 0 + if last_start: + try: + index = filenames.index(anchor, 0, last_start) + except ValueError: + print 'Anchor not found:', anchor + else: + print 'Anchor not found:', anchor # just use index = 0 if count > 0: index += 1 diff --git a/plugins/music/music.py b/plugins/music/music.py index b2f257d..aeef452 100644 --- a/plugins/music/music.py +++ b/plugins/music/music.py @@ -276,6 +276,7 @@ class Music(Plugin): self.files = files self.unsorted = True self.sortby = None + self.last_start = 0 def build_recursive_list(path, recurse=True): files = [] @@ -363,7 +364,10 @@ class Music(Plugin): files = filelist.files[:] # Trim the list - return self.item_count(handler, query, cname, files) + files, total, start = self.item_count(handler, query, cname, files, + filelist.last_start) + filelist.last_start = start + return files, total, start def get_playlist(self, handler, query): subcname = query['Container'][0] diff --git a/plugins/photo/photo.py b/plugins/photo/photo.py index 36ce6cb..553561b 100644 --- a/plugins/photo/photo.py +++ b/plugins/photo/photo.py @@ -322,6 +322,7 @@ class Photo(Plugin): self.files = files self.unsorted = True self.sortby = None + self.last_start = 0 self.lock = threading.RLock() def acquire(self, blocking=1): @@ -426,7 +427,6 @@ class Photo(Plugin): filelist.unsorted = False files = filelist.files[:] - filelist.release() # Filter it -- this section needs work if 'Filter' in query: @@ -437,4 +437,8 @@ class Photo(Plugin): elif usedir and not useimg: files = [x for x in files if x.isdir] - return self.item_count(handler, query, cname, files) + files, total, start = self.item_count(handler, query, cname, files, + filelist.last_start) + filelist.last_start = start + filelist.release() + return files, total, start -- 2.11.4.GIT