Ignore update with incomplete data when complete data is already cached
This commit is contained in:
parent
ffdf7d71e1
commit
2cb6caea8d
@ -295,4 +295,9 @@ class ComicCacher:
|
||||
set_slots += key + " = ?"
|
||||
|
||||
sql_ins = f"INSERT OR REPLACE INTO {tablename} ({keys}) VALUES ({ins_slots})"
|
||||
if not data.get("complete", True):
|
||||
sql_ins += f" ON CONFLICT DO UPDATE SET {set_slots} WHERE complete != ?"
|
||||
vals.extend(vals)
|
||||
vals.append(True) # If the cache is complete and this isn't complete we don't update it
|
||||
|
||||
cur.execute(sql_ins, vals)
|
||||
|
@ -28,10 +28,32 @@ def test_search_results(comic_cache):
|
||||
@pytest.mark.parametrize("series_info", search_results)
|
||||
def test_series_info(comic_cache, series_info):
|
||||
comic_cache.add_series_info(
|
||||
series=comictalker.comiccacher.Series(id=series_info["id"], data=json.dumps(series_info)),
|
||||
series=comictalker.comiccacher.Series(id=series_info["id"], data=json.dumps(series_info).encode("utf-8")),
|
||||
source="test",
|
||||
complete=True,
|
||||
)
|
||||
vi = series_info.copy()
|
||||
cache_result = json.loads(comic_cache.get_series_info(series_id=series_info["id"], source="test")[0].data)
|
||||
assert vi == cache_result
|
||||
|
||||
|
||||
@pytest.mark.parametrize("series_info", search_results)
|
||||
def test_cache_overwrite(comic_cache, series_info):
|
||||
vi = series_info.copy()
|
||||
comic_cache.add_series_info(
|
||||
series=comictalker.comiccacher.Series(id=series_info["id"], data=json.dumps(series_info).encode("utf-8")),
|
||||
source="test",
|
||||
complete=True,
|
||||
) # Populate the cache
|
||||
|
||||
# Try to insert an incomplete series with different data
|
||||
series_info["name"] = "test 3"
|
||||
comic_cache.add_series_info(
|
||||
series=comictalker.comiccacher.Series(id=series_info["id"], data=json.dumps(series_info).encode("utf-8")),
|
||||
source="test",
|
||||
complete=False,
|
||||
)
|
||||
cache_result = json.loads(comic_cache.get_series_info(series_id=series_info["id"], source="test")[0].data)
|
||||
|
||||
# Validate that the Series marked complete is still in the cache
|
||||
assert vi == cache_result
|
||||
|
Loading…
Reference in New Issue
Block a user