Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correctly refresh exceptions cache #11652

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion medusa/scene_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def refresh_exceptions_cache(series_obj=None):
logger.info('Updating exception_cache and exception_season_cache')

# Empty the module level variables
exceptions_cache.clear()
if not series_obj:
exceptions_cache.clear()
else:
exceptions_cache[(series_obj.indexer, series_obj.series_id)].clear()

main_db_con = db.DBConnection()
query = """
Expand Down
46 changes: 46 additions & 0 deletions tests/test_scene_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# coding=utf-8
"""Tests for medusa.scene_exceptions module."""

from medusa.scene_exceptions import refresh_exceptions_cache, get_season_from_name

def test_referesh_series(monkeypatch_function_return, create_tvshow):
series1 = create_tvshow(indexerid=1, name='series1')
series2 = create_tvshow(indexerid=2, name='series2')

# do an initial load of all exceptions
initial_exceptions = [('medusa.db.DBConnection.select', [
{
'indexer': 1,
'series_id': 1,
'season': 1,
'title': 'exception1',
'custom': False
},
{
'indexer': 1,
'series_id': 2,
'season': 1,
'title': 'exception2',
'custom': False
}])]
monkeypatch_function_return(initial_exceptions)
refresh_exceptions_cache()

assert get_season_from_name(series1, 'exception1') == 1
assert get_season_from_name(series2, 'exception2') == 1

# only refresh series2
series_exceptions = [('medusa.db.DBConnection.select', [
{
'indexer': 1,
'series_id': 2,
'season': 2,
'title': 'exception2 modified',
'custom': False
}])]
monkeypatch_function_return(series_exceptions)
refresh_exceptions_cache(series_obj=series2)

# both series should be present in the exceptions cache
assert get_season_from_name(series1, 'exception1') == 1
assert get_season_from_name(series2, 'exception2 modified') == 2
Loading