Commit 0f190e05 authored by echel0n's avatar echel0n

Added function to check database index data integrity and rebuild if failed

parent 7c31b0c7
# Changelog
- * 62c1ce5 - 2018-11-10: Fixed issue for missing database indexes.
- * 5582a1e - 2018-11-10: Added function to check database index data integrity and rebuild if failed
- * 7c31b0c - 2018-11-10: Fixed issue for missing database indexes.
- * 3f20cdd - 2018-11-10: Refactored misc errors to warnings.
- * 4127ed3 - 2018-11-10: Refactored misc errors to warnings.
- * 78c64b1 - 2018-11-10: Release v9.4.26
......
......@@ -225,17 +225,35 @@ class srDatabase(object):
def check_integrity(self):
for index_name in self._indexes:
try:
for x in self.db.all(index_name):
try:
self.get('id', x.get('_id'))
except (ValueError, TypeError) as e:
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])
sickrage.app.log.debug('Checking data integrity for index {}'.format(index_name))
data = []
failed = False
# check integrity of index data
for x in self.db.all(index_name):
try:
data += [self.get('id', x.get('_id'))]
except Exception:
failed = True
# check if we failed integrity check, if so then destroy index
if failed and index_name in self.db.indexes_names:
self.db.destroy_index(self.db.indexes_names[index_name])
# check if index exists, if not then add it
if index_name not in self.db.indexes_names:
self.db.add_index(self._indexes[index_name](self.db.path, index_name))
#self.db.reindex_index(index_name)
# rebuild index if failed
if failed:
sickrage.app.log.debug('Failed data integrity check, rebuilding index {}'.format(index_name))
for x in data:
del x['_id'], x['_rev']
self.insert(x)
# cleanup
del data
def migrate(self):
if os.path.isfile(self.old_db_path):
......
......@@ -522,7 +522,7 @@ class TVShow(object):
"Found episode by absolute_number %s which is S%02dE%02d" % (
absolute_number, season or 0, episode or 0))
elif len(dbData) > 1:
sickrage.app.log.error("Multiple entries for absolute number: " + str(
sickrage.app.log.warning("Multiple entries for absolute number: " + str(
absolute_number) + " in show: " + self.name + " found ")
return None
else:
......
Markdown is supported
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