Skip to content

Commit

Permalink
correctly refresh exceptions cache
Browse files Browse the repository at this point in the history
  • Loading branch information
j-aub committed Mar 17, 2024
1 parent 101dd20 commit 9da311d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
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

0 comments on commit 9da311d

Please sign in to comment.