Skip to content

Commit

Permalink
Fix bug comparing limit to cache limit
Browse files Browse the repository at this point in the history
  • Loading branch information
rajlaud committed Oct 26, 2020
1 parent 8797bd3 commit d6665da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 11 additions & 3 deletions pysqueezebox/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,17 @@ 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:
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][2]
if status["lastscan"] <= cached_category[0]:
if limit is None:
if cached_category[1] is None:
_LOGGER.debug("Using cached category %s", category)
return self.__dict__[category][2]
else:
if cached_category[1] is None or limit <= cached_category[1]:
_LOGGER.debug(
"Using cached category %s with limit %s", category, limit
)
return self.__dict__[category][2][:limit]

_LOGGER.debug("Updating cache for category %s", category)
if self.__dict__[category] is not None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pysqueezebox",
version="0.5.3",
version="0.5.4",
license="apache-2.0",
author="Raj Laud",
author_email="raj.laud@gmail.com",
Expand Down
7 changes: 5 additions & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,13 @@ async def test_browse(lms):
for category in categories:
await lookup_helper(lms, category[0], category[1])

# test lookup without limit
await lookup_helper(lms, "artists", "artist_id")

async def lookup_helper(lms, category, id_type):

async def lookup_helper(lms, category, id_type, limit=BROWSE_LIMIT):
"""Lookup a known item and make sure the name matches."""
result = await lms.async_browse(category, limit=BROWSE_LIMIT)
result = await lms.async_browse(category, limit)
assert result["title"] is not None
assert len(result["items"]) > 0
browse_id = result["items"][0].get("id")
Expand Down

0 comments on commit d6665da

Please sign in to comment.