Optimize Sanity Check SQL
Instead of SELECT COUNT(media_id) from mediaapi_thumbnail WHERE media_id NOT IN (SELECT media_id FROM mediaapi_media_repository); we do SELECT COUNT(media_id) from mediaapi_thumbnail WHERE NOT EXISTS (SELECT media_id FROM mediaapi_media_repository); Per Till's (@s7evink:matrix.org) suggestion. All credit to him
This commit is contained in:
parent
0a03429abf
commit
7a4d497353
@ -177,7 +177,7 @@ class MediaRepository:
|
|||||||
def sanity_check_thumbnails(self) -> None:
|
def sanity_check_thumbnails(self) -> None:
|
||||||
"""Warn if we have thumbnails in the db that do not refer to existing media"""
|
"""Warn if we have thumbnails in the db that do not refer to existing media"""
|
||||||
with self.conn.cursor() as cur:
|
with self.conn.cursor() as cur:
|
||||||
cur.execute("SELECT COUNT(media_id) from mediaapi_thumbnail WHERE media_id NOT IN (SELECT media_id FROM mediaapi_media_repository);")
|
cur.execute("SELECT COUNT(media_id) from mediaapi_thumbnail WHERE NOT EXISTS (SELECT media_id FROM mediaapi_media_repository);")
|
||||||
row = cur.fetchone()
|
row = cur.fetchone()
|
||||||
if row is not None and row[0]:
|
if row is not None and row[0]:
|
||||||
logging.error("You have {} thumbnails in your db that do not refer to media. This needs fixing (we don't do that)!".format(row[0]))
|
logging.error("You have {} thumbnails in your db that do not refer to media. This needs fixing (we don't do that)!".format(row[0]))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user