VeuReu commited on
Commit
c6f4cbd
·
1 Parent(s): 0a50cfa

Upload 7 files

Browse files
Files changed (1) hide show
  1. databases.py +53 -13
databases.py CHANGED
@@ -347,28 +347,68 @@ def get_audiodescription_history(sha1sum: str, version: str) -> list[sqlite3.Row
347
  """
348
 
349
  try:
 
 
 
 
 
350
  print(
351
- f"[DEBUG] get_audiodescription_history sha1sum={sha1sum}, version={version}, DB={AUDIODESCRIPTIONS_DB_PATH}"
 
 
 
352
  )
 
 
 
353
  with _connect_audiodescriptions_db() as conn:
354
- # Ordenem principalment per created_at/updated_at si existeixen, amb fallback a rowid
355
- cur = conn.execute(
356
- """
357
- SELECT * FROM audiodescriptions
358
- WHERE sha1sum = ? AND version = ?
359
- ORDER BY
360
- COALESCE(created_at, updated_at, '') ASC,
361
- rowid ASC
362
- """,
363
- (sha1sum, version),
364
- )
365
  rows = cur.fetchall() or []
366
  print(f"[DEBUG] get_audiodescription_history returned {len(rows)} row(s)")
367
  if rows:
368
  try:
369
- print(f"[DEBUG] get_audiodescription_history first row keys: {list(rows[0].keys())}")
 
 
 
370
  except Exception:
371
  pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372
  return rows
373
  except sqlite3.OperationalError:
374
  return []
 
347
  """
348
 
349
  try:
350
+ sql = (
351
+ "SELECT * FROM audiodescriptions "
352
+ "WHERE sha1sum = ? AND version = ? "
353
+ "ORDER BY COALESCE(created_at, updated_at, '') ASC, rowid ASC"
354
+ )
355
  print(
356
+ "[DEBUG] get_audiodescription_history",
357
+ f"DB={AUDIODESCRIPTIONS_DB_PATH}",
358
+ f"sha1sum={sha1sum}",
359
+ f"version={version}",
360
  )
361
+ print(f"[DEBUG] get_audiodescription_history SQL: {sql}")
362
+ print(f"[DEBUG] get_audiodescription_history params: {(sha1sum, version)}")
363
+
364
  with _connect_audiodescriptions_db() as conn:
365
+ # Consulta principal per a sha1sum+versió
366
+ cur = conn.execute(sql, (sha1sum, version))
 
 
 
 
 
 
 
 
 
367
  rows = cur.fetchall() or []
368
  print(f"[DEBUG] get_audiodescription_history returned {len(rows)} row(s)")
369
  if rows:
370
  try:
371
+ print(
372
+ "[DEBUG] get_audiodescription_history first row keys:",
373
+ list(rows[0].keys()),
374
+ )
375
  except Exception:
376
  pass
377
+
378
+ # Diagnòstic addicional: veure totes les versions disponibles per a aquest sha1sum
379
+ try:
380
+ cur2 = conn.execute(
381
+ """
382
+ SELECT sha1sum, version,
383
+ LENGTH(une_ad) AS len_une_ad,
384
+ LENGTH(free_ad) AS len_free_ad,
385
+ created_at, updated_at
386
+ FROM audiodescriptions
387
+ WHERE sha1sum = ?
388
+ ORDER BY version, created_at, rowid
389
+ """,
390
+ (sha1sum,),
391
+ )
392
+ diag_rows = cur2.fetchall() or []
393
+ summary = [
394
+ {
395
+ "version": r["version"],
396
+ "len_une_ad": r["len_une_ad"],
397
+ "len_free_ad": r["len_free_ad"],
398
+ "created_at": r["created_at"],
399
+ "updated_at": r["updated_at"],
400
+ }
401
+ for r in diag_rows
402
+ ]
403
+ print(
404
+ "[DEBUG] get_audiodescription_history versions for sha1sum",
405
+ sha1sum,
406
+ "->",
407
+ summary,
408
+ )
409
+ except Exception as e:
410
+ print(f"[DEBUG] get_audiodescription_history diag error: {e}")
411
+
412
  return rows
413
  except sqlite3.OperationalError:
414
  return []