mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-08 11:03:38 +00:00
Added code to check and confirm that a daily search was performed on previous cache results before we go ahead with clearing the cache and wasting results that could hold potential items to be snatched.
This commit is contained in:
parent
628fe23f8d
commit
25e2430820
2 changed files with 44 additions and 1 deletions
|
@ -27,6 +27,7 @@ class InitialSchema(db.SchemaUpgrade):
|
||||||
|
|
||||||
queries = [
|
queries = [
|
||||||
("CREATE TABLE lastUpdate (provider TEXT, time NUMERIC);",),
|
("CREATE TABLE lastUpdate (provider TEXT, time NUMERIC);",),
|
||||||
|
("CREATE TABLE lastSearch (provider TEXT, time NUMERIC);",),
|
||||||
("CREATE TABLE db_version (db_version INTEGER);",),
|
("CREATE TABLE db_version (db_version INTEGER);",),
|
||||||
("INSERT INTO db_version (db_version) VALUES (?)", 1),
|
("INSERT INTO db_version (db_version) VALUES (?)", 1),
|
||||||
]
|
]
|
||||||
|
@ -69,6 +70,7 @@ class AddXemNumbering(AddNetworkTimezones):
|
||||||
def execute(self):
|
def execute(self):
|
||||||
self.connection.action(
|
self.connection.action(
|
||||||
"CREATE TABLE xem_numbering (indexer TEXT, indexer_id INTEGER, season INTEGER, episode INTEGER, scene_season INTEGER, scene_episode INTEGER)")
|
"CREATE TABLE xem_numbering (indexer TEXT, indexer_id INTEGER, season INTEGER, episode INTEGER, scene_season INTEGER, scene_episode INTEGER)")
|
||||||
|
|
||||||
class AddXemRefresh(AddXemNumbering):
|
class AddXemRefresh(AddXemNumbering):
|
||||||
def test(self):
|
def test(self):
|
||||||
return self.hasTable("xem_refresh")
|
return self.hasTable("xem_refresh")
|
||||||
|
@ -120,3 +122,9 @@ class RemoveKeysFromXemNumbering(ConvertIndexerToInteger):
|
||||||
self.connection.action("ALTER TABLE xem_numbering DROP UNIQUE (indexer, indexer_id, season, episode)")
|
self.connection.action("ALTER TABLE xem_numbering DROP UNIQUE (indexer, indexer_id, season, episode)")
|
||||||
self.connection.action("ALTER TABLE xem_numbering DROP PRIMARY KEY")
|
self.connection.action("ALTER TABLE xem_numbering DROP PRIMARY KEY")
|
||||||
|
|
||||||
|
class AddLastSearch(RemoveKeysFromXemNumbering):
|
||||||
|
def test(self):
|
||||||
|
return self.hasTable("lastSearch")
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
self.connection.action("CREATE TABLE lastSearch (provider TEXT, time NUMERIC)")
|
||||||
|
|
|
@ -80,6 +80,8 @@ class TVCache():
|
||||||
return CacheDBConnection(self.providerID)
|
return CacheDBConnection(self.providerID)
|
||||||
|
|
||||||
def _clearCache(self):
|
def _clearCache(self):
|
||||||
|
if not self.shouldClearCache():
|
||||||
|
return
|
||||||
|
|
||||||
myDB = self._getDB()
|
myDB = self._getDB()
|
||||||
|
|
||||||
|
@ -201,6 +203,19 @@ class TVCache():
|
||||||
|
|
||||||
return datetime.datetime.fromtimestamp(lastTime)
|
return datetime.datetime.fromtimestamp(lastTime)
|
||||||
|
|
||||||
|
def _getLastSearch(self):
|
||||||
|
myDB = self._getDB()
|
||||||
|
sqlResults = myDB.select("SELECT time FROM lastSearch WHERE provider = ?", [self.providerID])
|
||||||
|
|
||||||
|
if sqlResults:
|
||||||
|
lastTime = int(sqlResults[0]["time"])
|
||||||
|
if lastTime > int(time.mktime(datetime.datetime.today().timetuple())):
|
||||||
|
lastTime = 0
|
||||||
|
else:
|
||||||
|
lastTime = 0
|
||||||
|
|
||||||
|
return datetime.datetime.fromtimestamp(lastTime)
|
||||||
|
|
||||||
|
|
||||||
def setLastUpdate(self, toDate=None):
|
def setLastUpdate(self, toDate=None):
|
||||||
if not toDate:
|
if not toDate:
|
||||||
|
@ -211,9 +226,18 @@ class TVCache():
|
||||||
{'time': int(time.mktime(toDate.timetuple()))},
|
{'time': int(time.mktime(toDate.timetuple()))},
|
||||||
{'provider': self.providerID})
|
{'provider': self.providerID})
|
||||||
|
|
||||||
|
def setLastSearch(self, toDate=None):
|
||||||
|
if not toDate:
|
||||||
|
toDate = datetime.datetime.today()
|
||||||
|
|
||||||
|
myDB = self._getDB()
|
||||||
|
myDB.upsert("lastSearch",
|
||||||
|
{'time': int(time.mktime(toDate.timetuple()))},
|
||||||
|
{'provider': self.providerID})
|
||||||
|
|
||||||
|
|
||||||
lastUpdate = property(_getLastUpdate)
|
lastUpdate = property(_getLastUpdate)
|
||||||
|
lastSearch = property(_getLastSearch)
|
||||||
|
|
||||||
def shouldUpdate(self):
|
def shouldUpdate(self):
|
||||||
# if we've updated recently then skip the update
|
# if we've updated recently then skip the update
|
||||||
|
@ -224,6 +248,14 @@ class TVCache():
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def shouldClearCache(self):
|
||||||
|
# if daily search hasn't used our previous results yet then don't clear the cache
|
||||||
|
if self.lastUpdate > self.lastSearch:
|
||||||
|
logger.log(
|
||||||
|
u"Daily search has not yet searched our last cache results, skipping clearig cache ...", logger.DEBUG)
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def _addCacheEntry(self, name, url, quality=None):
|
def _addCacheEntry(self, name, url, quality=None):
|
||||||
indexerid = None
|
indexerid = None
|
||||||
|
@ -392,5 +424,8 @@ class TVCache():
|
||||||
else:
|
else:
|
||||||
neededEps[epObj].append(result)
|
neededEps[epObj].append(result)
|
||||||
|
|
||||||
|
# datetime stamp this search so cache gets cleared
|
||||||
|
self.setLastSearch()
|
||||||
|
|
||||||
return neededEps
|
return neededEps
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue