Commit 5c4b8228 authored by echel0n's avatar echel0n
Browse files

refactored remaining GET database calls

parent c07404b6
# Changelog
- * 219ae81 - 2017-12-11: Fixed issues with SkyTorrents
- * dcebc53 - 2017-12-11: refactored remaining GET database calls
- * c07404b - 2017-12-11: Fixed issues with SkyTorrents
- * 8923500 - 2017-12-11: Fixed issues with failed and cache database md5 checksums
- * 93c5ad5 - 2017-12-11: Fixed issues with failed and cache database cleanup on new revs
- * 8e43de8 - 2017-12-11: Fixed issues with removing duplicate shows and episodes
......
......@@ -86,7 +86,7 @@ class BlackAndWhiteList(object):
:param table: database table remove keywords from
"""
try:
sickrage.app.main_db.delete(sickrage.app.main_db.get(table, self.show_id, with_doc=True)['doc'])
sickrage.app.main_db.delete(sickrage.app.main_db.get(table, self.show_id))
except RecordNotFound:
pass
......
......@@ -120,7 +120,7 @@ class TVCache(object):
@property
def last_update(self):
try:
dbData = sickrage.app.cache_db.get('lastUpdate', self.providerID, with_doc=True)['doc']
dbData = sickrage.app.cache_db.get('lastUpdate', self.providerID)
lastTime = int(dbData["time"])
if lastTime > int(time.mktime(datetime.datetime.today().timetuple())): lastTime = 0
except RecordNotFound:
......@@ -131,7 +131,7 @@ class TVCache(object):
@last_update.setter
def last_update(self, toDate):
try:
dbData = sickrage.app.cache_db.get('lastUpdate', self.providerID, with_doc=True)['doc']
dbData = sickrage.app.cache_db.get('lastUpdate', self.providerID)
dbData['time'] = int(time.mktime(toDate.timetuple()))
sickrage.app.cache_db.update(dbData)
except RecordNotFound:
......@@ -144,7 +144,7 @@ class TVCache(object):
@property
def last_search(self):
try:
dbData = sickrage.app.cache_db.get('lastSearch', self.providerID, with_doc=True)['doc']
dbData = sickrage.app.cache_db.get('lastSearch', self.providerID)
lastTime = int(dbData["time"])
if lastTime > int(time.mktime(datetime.datetime.today().timetuple())): lastTime = 0
except RecordNotFound:
......@@ -155,7 +155,7 @@ class TVCache(object):
@last_search.setter
def last_search(self, toDate):
try:
dbData = sickrage.app.cache_db.get('lastSearch', self.providerID, with_doc=True)['doc']
dbData = sickrage.app.cache_db.get('lastSearch', self.providerID)
dbData['time'] = int(time.mktime(toDate.timetuple()))
sickrage.app.cache_db.update(dbData)
except RecordNotFound:
......
......@@ -207,9 +207,9 @@ class srDatabase(object):
try:
for x in self.db.all(index_name):
try:
self.get('id', x.get('_id'), with_doc=True)
self.get('id', x.get('_id'))
except (ValueError, TypeError) as e:
self.delete(self.get(index_name, x.get('key'), with_doc=True)['doc'])
self.delete(self.get(index_name, x.get('key')))
except Exception as e:
if index_name in self.db.indexes_names:
self.db.destroy_index(self.db.indexes_names[index_name])
......@@ -302,7 +302,9 @@ class srDatabase(object):
return (x['doc'] for x in self.db.get_many(*args, **kwargs))
def get(self, *args, **kwargs):
return self.db.get(*args, **kwargs)
kwargs['with_doc'] = True
data = self.db.get(*args, **kwargs)
return data.get('doc', data)
def delete(self, *args):
return self.db.delete(*args)
......
......@@ -144,6 +144,6 @@ class MainDB(srDatabase):
def fix_orphaned_episodes(self):
for ep in self.all('tv_episodes'):
if not self.get('tv_shows', ep['showid'], with_doc=True)['doc']:
if not self.get('tv_shows', ep['showid']):
sickrage.app.log.info("Deleting orphan episode with id: {}".format(ep["indexerid"]))
self.delete(ep)
......@@ -52,7 +52,7 @@ def shouldRefresh(exList):
MAX_REFRESH_AGE_SECS = 86400 # 1 day
try:
dbData = sickrage.app.cache_db.get('scene_exceptions_refresh', exList, with_doc=True)['doc']
dbData = sickrage.app.cache_db.get('scene_exceptions_refresh', exList)
lastRefresh = int(dbData['last_refreshed'])
return int(time.mktime(datetime.datetime.today().timetuple())) > lastRefresh + MAX_REFRESH_AGE_SECS
except RecordNotFound:
......@@ -66,7 +66,7 @@ def setLastRefresh(exList):
:param exList: exception list to set refresh time
"""
try:
dbData = sickrage.app.cache_db.get('scene_exceptions_refresh', exList, with_doc=True)['doc']
dbData = sickrage.app.cache_db.get('scene_exceptions_refresh', exList)
dbData['last_refreshed'] = int(time.mktime(datetime.datetime.today().timetuple()))
sickrage.app.cache_db.update(dbData)
except RecordNotFound:
......
......@@ -479,7 +479,7 @@ def xem_refresh(indexer_id, indexer, force=False):
MAX_REFRESH_AGE_SECS = 86400 # 1 day
try:
dbData = sickrage.app.main_db.get('xem_refresh', indexer_id, with_doc=True)['doc']
dbData = sickrage.app.main_db.get('xem_refresh', indexer_id)
lastRefresh = try_int(dbData['last_refreshed'])
refresh = int(time.mktime(datetime.datetime.today().timetuple())) > lastRefresh + MAX_REFRESH_AGE_SECS
except RecordNotFound:
......@@ -491,7 +491,7 @@ def xem_refresh(indexer_id, indexer, force=False):
# mark refreshed
try:
dbData = sickrage.app.main_db.get('xem_refresh', indexer_id, with_doc=True)['doc']
dbData = sickrage.app.main_db.get('xem_refresh', indexer_id)
dbData['last_refreshed'] = int(time.mktime(datetime.datetime.today().timetuple()))
sickrage.app.main_db.update(dbData)
except RecordNotFound:
......
......@@ -935,7 +935,7 @@ class TVShow(object):
'last_update'
]
dbData = sickrage.app.main_db.get('imdb_info', self.indexerid, with_doc=True)['doc']
dbData = sickrage.app.main_db.get('imdb_info', self.indexerid)
self._imdb_info = {k: dbData[k] for k in imdb_info_keys if k in dbData}
except RecordNotFound:
pass
......@@ -1271,7 +1271,7 @@ class TVShow(object):
}
try:
dbData = sickrage.app.main_db.get('tv_shows', self.indexerid, with_doc=True)['doc']
dbData = sickrage.app.main_db.get('tv_shows', self.indexerid)
dbData.update(tv_show)
sickrage.app.main_db.update(dbData)
except RecordNotFound:
......@@ -1279,7 +1279,7 @@ class TVShow(object):
if self.imdbid and self.imdb_info:
try:
dbData = sickrage.app.main_db.get('imdb_info', self.indexerid, with_doc=True)['doc']
dbData = sickrage.app.main_db.get('imdb_info', self.indexerid)
dbData.update(self.imdb_info)
sickrage.app.main_db.update(dbData)
except RecordNotFound:
......
......@@ -48,7 +48,7 @@ class ShowUpdater(object):
update_timestamp = int(time.mktime(datetime.datetime.now().timetuple()))
try:
dbData = sickrage.app.cache_db.get('lastUpdate', 'theTVDB', with_doc=True)['doc']
dbData = sickrage.app.cache_db.get('lastUpdate', 'theTVDB')
last_update = int(dbData['time'])
except RecordNotFound:
last_update = update_timestamp
......
......@@ -70,7 +70,7 @@ def update_network_dict():
})
elif network_dict[network] is not timezone:
try:
dbData = sickrage.app.cache_db.get('network_timezones', network, with_doc=True)['doc']
dbData = sickrage.app.cache_db.get('network_timezones', network)
dbData['timezone'] = timezone
sickrage.app.cache_db.update(dbData)
except RecordNotFound:
......@@ -81,8 +81,7 @@ def update_network_dict():
for x in network_dict:
try:
sickrage.app.cache_db.delete(
sickrage.app.cache_db.get('network_timezones', x, with_doc=True)['doc'])
sickrage.app.cache_db.delete(sickrage.app.cache_db.get('network_timezones', x))
except RecordNotFound:
continue
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment