@@ -101,17 +101,18 @@ def discovery_strategy_snapshot(
101101 parameters : tuple [Any , ...] = (platform ,) if platform else ()
102102 where = "WHERE platform=?" if platform else ""
103103 rows = connection .execute (
104- f"""SELECT platform,state,scan_json,candidate_json FROM source_jobs { where } """ ,
104+ f"""SELECT platform,state,
105+ COALESCE(json_extract(candidate_json,
106+ '$[0].discovery_quality_key'),'legacy') AS quality_key,
107+ COUNT(*) AS sources,
108+ SUM(CASE WHEN scan_json IS NULL THEN 0 ELSE 1 END) AS scan_evaluated
109+ FROM source_jobs { where }
110+ GROUP BY platform,state,quality_key""" ,
105111 parameters ,
106112 ).fetchall ()
107113 aggregates : dict [str , dict [str , Any ]] = {}
108114 for row in rows :
109- try :
110- candidates = json .loads (row ["candidate_json" ])
111- base = candidates [0 ] if candidates else {}
112- except (json .JSONDecodeError , TypeError ):
113- base = {}
114- key = str (base .get ("discovery_quality_key" ) or "legacy" )
115+ key = str (row ["quality_key" ] or "legacy" )
115116 item = aggregates .setdefault (
116117 key ,
117118 {
@@ -127,15 +128,16 @@ def discovery_strategy_snapshot(
127128 },
128129 )
129130 state = str (row ["state" ])
130- item ["sources" ] += 1
131- item ["platforms" ][str (row ["platform" ])] += 1
132- item ["states" ][state ] += 1
131+ sources = int (row ["sources" ])
132+ evaluated = int (row ["scan_evaluated" ] or 0 )
133+ item ["sources" ] += sources
134+ item ["platforms" ][str (row ["platform" ])] += sources
135+ item ["states" ][state ] += sources
133136 if state in ACTIVE_STATES :
134- item ["active_sources" ] += 1
135- if row ["scan_json" ]:
136- item ["scan_evaluated_sources" ] += 1
137- if state in {"scanned" , "complete" }:
138- item ["scan_passed_sources" ] += 1
137+ item ["active_sources" ] += sources
138+ item ["scan_evaluated_sources" ] += evaluated
139+ if state in {"scanned" , "complete" }:
140+ item ["scan_passed_sources" ] += evaluated
139141 if catalog_path and catalog_path .exists ():
140142 catalog = sqlite3 .connect (f"file:{ catalog_path } ?mode=ro" , uri = True , timeout = 30 )
141143 query = (
0 commit comments