From c09719063f3c0cca279e131defbbfb940fa3581f Mon Sep 17 00:00:00 2001 From: p0psicles Date: Sat, 16 Jul 2022 09:28:32 +0200 Subject: [PATCH 1/3] Fix dogpile keys for recommended shows. * Should fix the large recommended.dbm cache files. --- medusa/show/recommendations/anidb.py | 11 ++++++++++- medusa/show/recommendations/recommended.py | 9 ++++++++- medusa/show/recommendations/trakt.py | 11 ++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/medusa/show/recommendations/anidb.py b/medusa/show/recommendations/anidb.py index 0c8d2a00e6..f8a1adc233 100644 --- a/medusa/show/recommendations/anidb.py +++ b/medusa/show/recommendations/anidb.py @@ -26,6 +26,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' @@ -42,7 +51,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: diff --git a/medusa/show/recommendations/recommended.py b/medusa/show/recommendations/recommended.py index 01b46a1594..142dd84836 100644 --- a/medusa/show/recommendations/recommended.py +++ b/medusa/show/recommendations/recommended.py @@ -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 diff --git a/medusa/show/recommendations/trakt.py b/medusa/show/recommendations/trakt.py index 6784924df2..ecf0e4eb67 100644 --- a/medusa/show/recommendations/trakt.py +++ b/medusa/show/recommendations/trakt.py @@ -36,6 +36,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. @@ -58,7 +67,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( From 40b7188ce837ac1f977d7b646f640f5f1d8407c4 Mon Sep 17 00:00:00 2001 From: p0psicles Date: Sat, 16 Jul 2022 09:30:44 +0200 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7282b37e4b..8562afaebe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) From 7ad0f4792d3be7df54ee748e4a87b943b4ac66fe Mon Sep 17 00:00:00 2001 From: p0psicles Date: Sat, 16 Jul 2022 09:37:01 +0200 Subject: [PATCH 3/3] Fix flake --- medusa/show/recommendations/anidb.py | 1 - medusa/show/recommendations/trakt.py | 1 - 2 files changed, 2 deletions(-) diff --git a/medusa/show/recommendations/anidb.py b/medusa/show/recommendations/anidb.py index f8a1adc233..bbdd627b9a 100644 --- a/medusa/show/recommendations/anidb.py +++ b/medusa/show/recommendations/anidb.py @@ -15,7 +15,6 @@ MissingTvdbMapping, RecommendedShow, cached_aid_to_tvdb, - create_key_from_series, ) from simpleanidb import Anidb, REQUEST_HOT diff --git a/medusa/show/recommendations/trakt.py b/medusa/show/recommendations/trakt.py index ecf0e4eb67..3228da0fd8 100644 --- a/medusa/show/recommendations/trakt.py +++ b/medusa/show/recommendations/trakt.py @@ -18,7 +18,6 @@ from medusa.show.recommendations.recommended import ( BasePopular, RecommendedShow, - create_key_from_series, ) from six import iteritems