[39] reduce anidb calls

pull/1052/head
meisnate12 2 years ago
parent 42be739cdd
commit eaf0c2fe5d

@ -1 +1 @@
1.17.3-develop38
1.17.3-develop39

@ -83,13 +83,21 @@ class AniDB:
def authorize(self, client, version, expiration):
self.client = client
self.version = version
logger.secret(self.client)
self.expiration = expiration
logger.secret(self.client)
if self.config.Cache:
value1, value2, success = self.config.Cache.query_testing("anidb_login")
if str(value1) == str(client) and str(value2) == str(version) and success:
return
try:
self.get_anime(69, ignore_cache=True)
if self.config.Cache:
self.config.Cache.update_testing("anidb_login", self.client, self.version, "True")
except Failed:
self.client = None
self.version = None
if self.config.Cache:
self.config.Cache.update_testing("anidb_login", self.client, self.version, "False")
raise
@property

@ -268,6 +268,14 @@ class Cache:
type TEXT,
text TEXT)"""
)
cursor.execute(
"""CREATE TABLE IF NOT EXISTS testing (
key INTEGER PRIMARY KEY,
name TEXT,
value1 TEXT,
value2 TEXT,
success TEXT)"""
)
cursor.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='image_map'")
if cursor.fetchone()[0] > 0:
cursor.execute(f"SELECT DISTINCT library FROM image_map")
@ -935,3 +943,26 @@ class Cache:
with closing(connection.cursor()) as cursor:
cursor.execute("INSERT OR IGNORE INTO overlay_special_text(rating_key, type) VALUES(?, ?)", (rating_key, data_type))
cursor.execute("UPDATE overlay_special_text SET text = ? WHERE rating_key = ? AND type = ?", (text, rating_key, data_type))
def query_testing(self, name):
value1 = None
value2 = None
success = None
with sqlite3.connect(self.cache_path) as connection:
connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor:
cursor.execute(f"SELECT * FROM testing WHERE name = ?", (name,))
row = cursor.fetchone()
if row:
value1 = row["value1"]
value2 = row["value2"]
success = True if row["success"] == "True" else False
return value1, value2, success
def update_testing(self, name, value1, value2, success):
with sqlite3.connect(self.cache_path) as connection:
connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor:
cursor.execute(f"INSERT OR IGNORE INTO testing(name) VALUES(?)", (name,))
sql = f"UPDATE testing SET value1 = ?, value2 = ?, success = ? WHERE name = ?"
cursor.execute(sql, (value1, value2, success, name))

Loading…
Cancel
Save