feat: cache HLTB search responses
Store search results in hltb_cache (schema v8) with a 7-day TTL, cache misses too, prune rows older than 90 days, and add --cache-ttl, --no-cache and --clear-cache.
This commit is contained in:
1 parent
e82d0e0f0a
commit
987e52931f
6 files changed
+216
-18
No files matched your search
+15
-1
@@ -8,7 +8,7 @@ from datetime import datetime, timezone
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
DEFAULT_DB = os.path.join(BASE_DIR, "steam.db")
|
||||
SCHEMA_PATH = os.path.join(BASE_DIR, "tools", "schema.sql")
|
||||
SCHEMA_VERSION = 7
|
||||
SCHEMA_VERSION = 8
|
||||
|
||||
MOOD_PRESETS = {
|
||||
"adventure-rpg-party": {
|
||||
@@ -568,6 +568,19 @@ def _migration_7(con):
|
||||
_ensure_column(con, "games", "hltb_match", "INTEGER")
|
||||
|
||||
|
||||
def _migration_8(con):
|
||||
"""Cache HowLongToBeat search responses by query."""
|
||||
con.execute("""
|
||||
CREATE TABLE IF NOT EXISTS hltb_cache (
|
||||
query TEXT PRIMARY KEY,
|
||||
fetched_at TEXT NOT NULL,
|
||||
results TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
con.execute("CREATE INDEX IF NOT EXISTS idx_hltb_cache_fetched "
|
||||
"ON hltb_cache(fetched_at)")
|
||||
|
||||
|
||||
MIGRATIONS = {
|
||||
1: _migration_1,
|
||||
2: _migration_2,
|
||||
@@ -576,6 +589,7 @@ MIGRATIONS = {
|
||||
5: _migration_5,
|
||||
6: _migration_6,
|
||||
7: _migration_7,
|
||||
8: _migration_8,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user