Skip to content

Commit 1b2383d

Browse files
committed
Don't search again for unfound games when updating missing. They will only be checked again when a full sync is done.
fix(sync): marked unfound games to exclude from discovery queries
1 parent bbfa101 commit 1b2383d

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

web/routes/discover.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def discover(request: Request, conn: sqlite3.Connection = Depends(get_db)):
3535
igdb_summary, description, igdb_screenshots, total_rating,
3636
igdb_rating, aggregated_rating, genres, playtime_hours
3737
FROM games
38-
WHERE igdb_id IS NOT NULL""" + EXCLUDE_HIDDEN_FILTER + """
38+
WHERE igdb_id IS NOT NULL AND igdb_id > 0""" + EXCLUDE_HIDDEN_FILTER + """
3939
ORDER BY total_rating DESC NULLS LAST"""
4040
)
4141
library_games = cursor.fetchall()
@@ -119,7 +119,7 @@ def fetch_by_popularity_type(pop_type, limit=10):
119119
igdb_summary, description, igdb_screenshots, total_rating,
120120
igdb_rating, aggregated_rating, genres, playtime_hours
121121
FROM games
122-
WHERE igdb_id IS NOT NULL AND total_rating >= 90""" + EXCLUDE_HIDDEN_FILTER + """
122+
WHERE igdb_id IS NOT NULL AND igdb_id > 0 AND total_rating >= 90""" + EXCLUDE_HIDDEN_FILTER + """
123123
ORDER BY total_rating DESC
124124
LIMIT 10"""
125125
)
@@ -131,7 +131,7 @@ def fetch_by_popularity_type(pop_type, limit=10):
131131
igdb_summary, description, igdb_screenshots, total_rating,
132132
igdb_rating, aggregated_rating, genres, playtime_hours
133133
FROM games
134-
WHERE igdb_id IS NOT NULL
134+
WHERE igdb_id IS NOT NULL AND igdb_id > 0
135135
AND total_rating >= 75
136136
AND total_rating < 90
137137
AND aggregated_rating IS NULL""" + EXCLUDE_HIDDEN_FILTER + """
@@ -146,7 +146,7 @@ def fetch_by_popularity_type(pop_type, limit=10):
146146
igdb_summary, description, igdb_screenshots, total_rating,
147147
igdb_rating, aggregated_rating, genres, playtime_hours
148148
FROM games
149-
WHERE igdb_id IS NOT NULL AND playtime_hours > 0""" + EXCLUDE_HIDDEN_FILTER + """
149+
WHERE igdb_id IS NOT NULL AND igdb_id > 0 AND playtime_hours > 0""" + EXCLUDE_HIDDEN_FILTER + """
150150
ORDER BY playtime_hours DESC
151151
LIMIT 10"""
152152
)
@@ -158,7 +158,7 @@ def fetch_by_popularity_type(pop_type, limit=10):
158158
igdb_summary, description, igdb_screenshots, total_rating,
159159
igdb_rating, aggregated_rating, genres, playtime_hours
160160
FROM games
161-
WHERE igdb_id IS NOT NULL AND aggregated_rating >= 80""" + EXCLUDE_HIDDEN_FILTER + """
161+
WHERE igdb_id IS NOT NULL AND igdb_id > 0 AND aggregated_rating >= 80""" + EXCLUDE_HIDDEN_FILTER + """
162162
ORDER BY aggregated_rating DESC
163163
LIMIT 10"""
164164
)
@@ -170,7 +170,7 @@ def fetch_by_popularity_type(pop_type, limit=10):
170170
igdb_summary, description, igdb_screenshots, total_rating,
171171
igdb_rating, aggregated_rating, genres, playtime_hours
172172
FROM games
173-
WHERE igdb_id IS NOT NULL""" + EXCLUDE_HIDDEN_FILTER + """
173+
WHERE igdb_id IS NOT NULL AND igdb_id > 0""" + EXCLUDE_HIDDEN_FILTER + """
174174
ORDER BY RANDOM()
175175
LIMIT 10"""
176176
)

web/services/igdb_sync.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@ def sync_games(conn, client, limit=None, force=False):
374374

375375
if not results:
376376
print("No results")
377+
# Mark as searched but not found (igdb_id = 0)
378+
cursor.execute(
379+
"UPDATE games SET igdb_id = 0, igdb_matched_at = CURRENT_TIMESTAMP WHERE id = ?",
380+
(game_id,)
381+
)
382+
conn.commit()
377383
failed += 1
378384
continue
379385

@@ -460,6 +466,12 @@ def sync_games(conn, client, limit=None, force=False):
460466
matched += 1
461467
else:
462468
print(f"No good match (best score: {best_score:.0f})")
469+
# Mark as searched but not found (igdb_id = 0)
470+
cursor.execute(
471+
"UPDATE games SET igdb_id = 0, igdb_matched_at = CURRENT_TIMESTAMP WHERE id = ?",
472+
(game_id,)
473+
)
474+
conn.commit()
463475
failed += 1
464476

465477
# Rate limiting - IGDB allows 4 requests/second
@@ -479,7 +491,8 @@ def get_stats(conn):
479491
cursor.execute("SELECT COUNT(*) FROM games")
480492
total = cursor.fetchone()[0]
481493

482-
cursor.execute("SELECT COUNT(*) FROM games WHERE igdb_id IS NOT NULL")
494+
# Count matched games (igdb_id > 0, not counting 0 which means "not found")
495+
cursor.execute("SELECT COUNT(*) FROM games WHERE igdb_id IS NOT NULL AND igdb_id > 0")
483496
matched = cursor.fetchone()[0]
484497

485498
cursor.execute(

web/services/metacritic_sync.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,16 @@ def update_database(game_id, name, result):
377377
),
378378
)
379379

380+
def mark_not_found(name):
381+
"""Mark all games with this name as searched but not found (metacritic_score = -1)."""
382+
cursor.execute(
383+
"""UPDATE games SET
384+
metacritic_score = -1,
385+
metacritic_matched_at = CURRENT_TIMESTAMP
386+
WHERE LOWER(name) = LOWER(?)""",
387+
(name,),
388+
)
389+
380390
# Process games in parallel
381391
with ThreadPoolExecutor(max_workers=max_workers) as executor:
382392
# Submit all tasks
@@ -409,12 +419,18 @@ def update_database(game_id, name, result):
409419

410420
print(f"[{completed}/{total}] {name} → Matched: {result['match_name']} (match: {result['match_score']:.0f}){score_str}")
411421
else:
422+
# Mark as searched but not found
412423
with results_lock:
424+
mark_not_found(name)
425+
conn.commit()
413426
failed += 1
414427
print(f"[{completed}/{total}] {name}{result}")
415428

416429
except Exception as e:
430+
# Mark as searched but not found on exception
417431
with results_lock:
432+
mark_not_found(name)
433+
conn.commit()
418434
failed += 1
419435
print(f"[{completed}/{total}] {name} → Exception: {e}")
420436

@@ -428,11 +444,12 @@ def get_stats(conn):
428444
cursor.execute("SELECT COUNT(*) FROM games")
429445
total = cursor.fetchone()[0]
430446

431-
cursor.execute("SELECT COUNT(*) FROM games WHERE metacritic_score IS NOT NULL")
447+
# Count matched games (metacritic_score >= 0, not counting -1 which means "not found")
448+
cursor.execute("SELECT COUNT(*) FROM games WHERE metacritic_score IS NOT NULL AND metacritic_score >= 0")
432449
matched = cursor.fetchone()[0]
433450

434451
cursor.execute(
435-
"SELECT AVG(metacritic_score) FROM games WHERE metacritic_score IS NOT NULL"
452+
"SELECT AVG(metacritic_score) FROM games WHERE metacritic_score IS NOT NULL AND metacritic_score >= 0"
436453
)
437454
avg_critic_score = cursor.fetchone()[0]
438455

@@ -443,7 +460,7 @@ def get_stats(conn):
443460

444461
cursor.execute(
445462
"""SELECT name, metacritic_score FROM games
446-
WHERE metacritic_score IS NOT NULL
463+
WHERE metacritic_score IS NOT NULL AND metacritic_score >= 0
447464
ORDER BY metacritic_score DESC LIMIT 5"""
448465
)
449466
top_rated = cursor.fetchall()

0 commit comments

Comments
 (0)