Private GIT

Skip to content
Snippets Groups Projects
Commit 6ca25fd3 authored by Nic Wolfe's avatar Nic Wolfe
Browse files

Make RSS lookup caching more efficient

parent 64066a94
No related branches found
No related tags found
No related merge requests found
......@@ -85,12 +85,21 @@ def retrieve_exceptions():
exception_dict[tvdb_id] = alias_list
myDB = db.DBConnection("cache.db")
myDB.action("DELETE FROM scene_exceptions WHERE 1=1")
changed_exceptions = False
# write all the exceptions we got off the net into the database
for cur_tvdb_id in exception_dict:
# get a list of the existing exceptions for this ID
existing_exceptions = [x["show_name"] for x in myDB.select("SELECT * FROM scene_exceptions WHERE tvdb_id = ?", [cur_tvdb_id])]
for cur_exception in exception_dict[cur_tvdb_id]:
# if this exception isn't already in the DB then add it
if cur_exception not in existing_exceptions:
myDB.action("INSERT INTO scene_exceptions (tvdb_id, show_name) VALUES (?,?)", [cur_tvdb_id, cur_exception])
changed_exceptions = True
# since this could invalidate the results of the cache we clear it out after updating
if changed_exceptions:
name_cache.clearCache()
\ No newline at end of file
......@@ -3,7 +3,7 @@ import unittest
import sys, os.path
sys.path.append(os.path.abspath('..'))
from sickbeard import show_name_helpers, scene_exceptions, common
from sickbeard import show_name_helpers, scene_exceptions, common, name_cache
import sickbeard
from sickbeard import db
......@@ -108,6 +108,24 @@ class SceneExceptionTestCase(unittest.TestCase):
def test_sceneExceptionByNameEmpty(self):
self.assertEqual(scene_exceptions.get_scene_exception_by_name('nothing useful'), None)
def test_sceneExceptionsResetNameCache(self):
# clear the exceptions
myDB = db.DBConnection("cache.db")
myDB.action("DELETE FROM scene_exceptions")
# put something in the cache
name_cache.addNameToCache('Cached Name', 0)
# updating should clear the cache so our previously "Cached Name" won't be in there
scene_exceptions.retrieve_exceptions()
self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), None)
# put something in the cache
name_cache.addNameToCache('Cached Name', 0)
# updating should not clear the cache this time since our exceptions didn't change
scene_exceptions.retrieve_exceptions()
self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), 0)
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment