Hodfa71 commited on
Commit
757323c
·
verified ·
1 Parent(s): b8be610

Fix task count: read from manifest.json (simple, always correct)

Browse files
Files changed (1) hide show
  1. ls_proxy_hf.py +19 -20
ls_proxy_hf.py CHANGED
@@ -80,6 +80,22 @@ def _load_manifest_ids():
80
  _MANIFEST_IDS = _load_manifest_ids()
81
 
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  # ---------------------------------------------------------------------------
84
  # Annotation-submission email notifications
85
  # ---------------------------------------------------------------------------
@@ -670,18 +686,8 @@ def proxy_init():
670
  (uid, proj)
671
  ).fetchone()[0]
672
  conn.close()
673
- # Get authoritative task count via LS API (forwards user session)
674
- try:
675
- ls_resp = requests.get(
676
- f"{LS_URL}/api/projects/{proj}/",
677
- cookies=request.cookies,
678
- headers={"Accept": "application/json"},
679
- timeout=3
680
- )
681
- if ls_resp.status_code == 200:
682
- total = ls_resp.json().get("task_number", 0) or 0
683
- except Exception:
684
- pass
685
  except Exception:
686
  pass
687
  return Response(
@@ -1295,14 +1301,7 @@ def proxy_progress():
1295
  "WHERE tc.completed_by_id=? AND t.project_id=? AND tc.was_cancelled=0",
1296
  (uid, proj)
1297
  ).fetchone()[0]
1298
- total = conn.execute(
1299
- "SELECT COUNT(*) FROM task t WHERE t.project_id=? "
1300
- "AND NOT EXISTS ("
1301
- " SELECT 1 FROM core_deletedrow d "
1302
- " WHERE CAST(d.object_id AS INTEGER)=t.id"
1303
- ")",
1304
- (proj,)
1305
- ).fetchone()[0]
1306
  conn.close()
1307
  except Exception:
1308
  done, total = 0, 0
 
80
  _MANIFEST_IDS = _load_manifest_ids()
81
 
82
 
83
+ def _load_manifest_tasks():
84
+ """Return {project_id_str: task_count} from manifest.json."""
85
+ for candidate in [
86
+ os.path.join(os.path.dirname(os.path.abspath(__file__)), "projects", "manifest.json"),
87
+ "/app/projects/manifest.json",
88
+ ]:
89
+ try:
90
+ if os.path.exists(candidate):
91
+ return {str(e["id"]): int(e.get("tasks", 0)) for e in json.load(open(candidate))}
92
+ except Exception:
93
+ pass
94
+ return {}
95
+
96
+ _MANIFEST_TASKS = _load_manifest_tasks()
97
+
98
+
99
  # ---------------------------------------------------------------------------
100
  # Annotation-submission email notifications
101
  # ---------------------------------------------------------------------------
 
686
  (uid, proj)
687
  ).fetchone()[0]
688
  conn.close()
689
+ # Use manifest.json task count (always correct, avoids soft-delete complexity)
690
+ total = _MANIFEST_TASKS.get(str(proj), 0)
 
 
 
 
 
 
 
 
 
 
691
  except Exception:
692
  pass
693
  return Response(
 
1301
  "WHERE tc.completed_by_id=? AND t.project_id=? AND tc.was_cancelled=0",
1302
  (uid, proj)
1303
  ).fetchone()[0]
1304
+ total = _MANIFEST_TASKS.get(str(proj), 0)
 
 
 
 
 
 
 
1305
  conn.close()
1306
  except Exception:
1307
  done, total = 0, 0