Skip to content

Commit

Permalink
Fix dogpile keys for recommended shows. (pymedusa#10827)
Browse files Browse the repository at this point in the history
* Fix dogpile keys for recommended shows.
* Should fix the large recommended.dbm cache files.

* Update changelog

* Fix flake
  • Loading branch information
p0psicles authored and PaulLiang1 committed Oct 10, 2022
1 parent 4a3b93d commit f66149c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#### Fixes
- Fixed borders in tables where diplay: flex is used on a table cell. ([10813](https://github.com/pymedusa/Medusa/pull/10813))
- Fix keys for caching recommended shows in recommended.dbm. ([10827](https://github.com/pymedusa/Medusa/pull/10827))

## 1.0.5 (06-07-2022)

Expand Down
12 changes: 10 additions & 2 deletions medusa/show/recommendations/anidb.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
MissingTvdbMapping,
RecommendedShow,
cached_aid_to_tvdb,
create_key_from_series,
)

from simpleanidb import Anidb, REQUEST_HOT
Expand All @@ -26,6 +25,15 @@
log.logger.addHandler(logging.NullHandler())


def create_key_from_anidb_series(namespace, fn, **kw):
"""Create a key made of indexer name and show ID."""
def generate_key(*args, **kw):
show_id = args[1].aid
show_key = f'{namespace}_{show_id}'
return show_key
return generate_key


class AnidbPopular(BasePopular): # pylint: disable=too-few-public-methods

TITLE = 'Anidb Popular'
Expand All @@ -42,7 +50,7 @@ def __init__(self):
self.source = EXTERNAL_ANIDB
self.base_url = 'https://anidb.net/perl-bin/animedb.pl?show=anime&aid={aid}'

@recommended_series_cache.cache_on_arguments(namespace='anidb', function_key_generator=create_key_from_series)
@recommended_series_cache.cache_on_arguments(namespace='anidb', function_key_generator=create_key_from_anidb_series)
def _create_recommended_show(self, series):
"""Create the RecommendedShow object from the returned showobj."""
try:
Expand Down
9 changes: 8 additions & 1 deletion medusa/show/recommendations/recommended.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,14 @@ def cached_get_imdb_series_genres(imdb_id):
def create_key_from_series(namespace, fn, **kw):
"""Create a key made of indexer name and show ID."""
def generate_key(*args, **kw):
show_key = f'{namespace}_{args[1]}'
if args[1].get('imdb_tt'):
show_id = args[1]['imdb_tt']
elif args[1].get('id'):
show_id = args[1]['id']
else:
raise Exception('Could not get a show id for dogpile caching.')

show_key = f'{namespace}_{show_id}'
return show_key
return generate_key

Expand Down
12 changes: 10 additions & 2 deletions medusa/show/recommendations/trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from medusa.show.recommendations.recommended import (
BasePopular,
RecommendedShow,
create_key_from_series,
)

from six import iteritems
Expand All @@ -36,6 +35,15 @@
missing_posters = ExpiringList(cache_timeout=3600 * 24 * 3) # Cache 3 days


def create_key_from_trakt_series(namespace, fn, **kw):
"""Create a key made of indexer name and show ID."""
def generate_key(*args, **kw):
show_id = args[1].trakt
show_key = f'{namespace}_{show_id}'
return show_key
return generate_key


class TraktPopular(BasePopular):
"""This class retrieves a speficed recommended show list from Trakt.
Expand All @@ -58,7 +66,7 @@ def __init__(self):
self.default_img_src = 'trakt-default.png'
self.tvdb_api_v2 = indexerApi(INDEXER_TVDBV2).indexer()

@recommended_series_cache.cache_on_arguments(namespace='trakt', function_key_generator=create_key_from_series)
@recommended_series_cache.cache_on_arguments(namespace='trakt', function_key_generator=create_key_from_trakt_series)
def _create_recommended_show(self, show, subcat=None):
"""Create the RecommendedShow object from the returned showobj."""
rec_show = RecommendedShow(
Expand Down

0 comments on commit f66149c

Please sign in to comment.