Skip to content

Commit

Permalink
Honor limit when updating browse cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rajlaud committed Oct 26, 2020
1 parent b76654e commit 27a8317
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pysqueezebox/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ async def async_query_category(self, category, limit=None, search=None):
query.append("tags:ju")

result = await self.async_query(*query)
if result is None or result.get('count') == 0:
if result is None or result.get("count") == 0:
return None

try:
Expand Down Expand Up @@ -291,25 +291,27 @@ async def async_get_category(self, category, limit=None, search=None):

status = await self.async_status()
if "lastscan" in status and self.__dict__[category] is not None:
if status["lastscan"] <= self.__dict__[category][0]:
cached_category = self.__dict__[category]
if status["lastscan"] <= cached_category[0] and limit <= cached_category[1]:
_LOGGER.debug("Using cached category %s", category)
return self.__dict__[category][1]
return self.__dict__[category][2]

_LOGGER.debug("Updating cache for category %s", category)
if self.__dict__[category]:
if self.__dict__[category] is not None:
_LOGGER.debug(
"Server lastscan %s different than playlist lastscan %s",
status.get("lastscan"),
self.__dict__[category][0],
)
else:
_LOGGER.debug("Category %s not set", category)
result = await self.async_query_category(category)
result = await self.async_query_category(category, limit=limit)
status = await self.async_status()
self.__dict__[category] = (status.get("lastscan", 0), result)
if limit and self.__dict__[category][1] is not None:
return self.__dict__[category][1][:limit]
return self.__dict__[category][1]
self.__dict__[category] = (status.get("lastscan"), limit, result)

if limit:
return self.__dict__[category][2][:limit]
return self.__dict__[category][2]

async def async_get_category_title(self, category, browse_id):
"""
Expand Down

0 comments on commit 27a8317

Please sign in to comment.