refactor: cargo fmt across 27 files + behavioral fixes
Behavioral changes: - postgres_db: reorder default processors (cut first), prevent overwriting completed status - qdrant_db: fix scroll pagination exit condition (next.is_none()) - job_worker: add idempotency guards for face trace / TKG build; better error logging - main.rs: add LineWriter for stdout buffering Remaining diff is cargo fmt reformatting (line wrapping, import ordering).
This commit is contained in:
+65
-32
@@ -164,8 +164,7 @@ async fn list_files(
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
|
||||
let count_map: std::collections::HashMap<String, i64> =
|
||||
chunk_counts.into_iter().collect();
|
||||
let count_map: std::collections::HashMap<String, i64> = chunk_counts.into_iter().collect();
|
||||
|
||||
for item in &mut data {
|
||||
if let Some(cnt) = count_map.get(&item.file_uuid) {
|
||||
@@ -483,13 +482,20 @@ async fn delete_identity(
|
||||
{"key": "identity_id", "match": {"value": identity_id}}
|
||||
]
|
||||
});
|
||||
let points = qdrant.scroll_all_points("_faces", face_filter, 1000).await.unwrap_or_default();
|
||||
let points = qdrant
|
||||
.scroll_all_points("_faces", face_filter, 1000)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
|
||||
let unbound_faces: Vec<(String, Option<String>, Option<i32>)> = points.iter()
|
||||
let unbound_faces: Vec<(String, Option<String>, Option<i32>)> = points
|
||||
.iter()
|
||||
.filter_map(|p| {
|
||||
let payload = &p["payload"];
|
||||
let file_uuid = payload["file_uuid"].as_str()?.to_string();
|
||||
let face_id = payload.get("face_id").and_then(|v| v.as_str()).map(|s| s.to_string());
|
||||
let face_id = payload
|
||||
.get("face_id")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.to_string());
|
||||
let trace_id = payload["trace_id"].as_i64().map(|t| t as i32);
|
||||
Some((file_uuid, face_id, trace_id))
|
||||
})
|
||||
@@ -629,8 +635,12 @@ async fn get_identity_files(
|
||||
{"key": "identity_id", "match": {"value": identity_id}}
|
||||
]
|
||||
});
|
||||
let points = qdrant.scroll_all_points("_faces", face_filter, 1000).await.unwrap_or_default();
|
||||
let unique_files: std::collections::HashSet<String> = points.iter()
|
||||
let points = qdrant
|
||||
.scroll_all_points("_faces", face_filter, 1000)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
let unique_files: std::collections::HashSet<String> = points
|
||||
.iter()
|
||||
.filter_map(|p| p["payload"]["file_uuid"].as_str().map(|s| s.to_string()))
|
||||
.collect();
|
||||
let total = unique_files.len() as i64;
|
||||
@@ -730,7 +740,10 @@ async fn get_identity_faces(
|
||||
{"key": "identity_id", "match": {"value": identity_id}}
|
||||
]
|
||||
});
|
||||
let points2 = qdrant2.scroll_all_points("_faces", face_filter2, 2000).await.unwrap_or_default();
|
||||
let points2 = qdrant2
|
||||
.scroll_all_points("_faces", face_filter2, 2000)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
let total = points2.len() as i64;
|
||||
|
||||
Ok(Json(IdentityFacesResponse {
|
||||
@@ -827,9 +840,7 @@ async fn get_file_faces(
|
||||
use serde_json::json;
|
||||
|
||||
let qdrant = QdrantDb::new();
|
||||
let mut filter_conditions = vec![
|
||||
json!({"key": "file_uuid", "match": {"value": file_uuid}})
|
||||
];
|
||||
let mut filter_conditions = vec![json!({"key": "file_uuid", "match": {"value": file_uuid}})];
|
||||
|
||||
if let Some(ref binding) = params.binding {
|
||||
match binding.as_str() {
|
||||
@@ -851,30 +862,46 @@ async fn get_file_faces(
|
||||
}
|
||||
|
||||
let face_filter = json!({"must": filter_conditions});
|
||||
let points = qdrant.scroll_all_points("_faces", face_filter, 2000).await.unwrap_or_default();
|
||||
let points = qdrant
|
||||
.scroll_all_points("_faces", face_filter, 2000)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
|
||||
// Apply additional filters in Rust
|
||||
let filtered: Vec<_> = points.into_iter().filter(|p| {
|
||||
let payload = &p["payload"];
|
||||
let confidence = payload["confidence"].as_f64().unwrap_or(0.0);
|
||||
let frame = payload["frame"].as_i64().unwrap_or(0);
|
||||
let filtered: Vec<_> = points
|
||||
.into_iter()
|
||||
.filter(|p| {
|
||||
let payload = &p["payload"];
|
||||
let confidence = payload["confidence"].as_f64().unwrap_or(0.0);
|
||||
let frame = payload["frame"].as_i64().unwrap_or(0);
|
||||
|
||||
if let Some(mc) = params.min_confidence {
|
||||
if confidence < mc { return false; }
|
||||
}
|
||||
if let Some(sf) = params.start_frame {
|
||||
if frame < sf { return false; }
|
||||
}
|
||||
if let Some(ef) = params.end_frame {
|
||||
if frame > ef { return false; }
|
||||
}
|
||||
true
|
||||
}).collect();
|
||||
if let Some(mc) = params.min_confidence {
|
||||
if confidence < mc {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if let Some(sf) = params.start_frame {
|
||||
if frame < sf {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if let Some(ef) = params.end_frame {
|
||||
if frame > ef {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
})
|
||||
.collect();
|
||||
|
||||
let total = filtered.len() as i64;
|
||||
|
||||
// Apply pagination
|
||||
let paged: Vec<_> = filtered.into_iter().skip(offset as usize).take(page_size as usize).collect();
|
||||
let paged: Vec<_> = filtered
|
||||
.into_iter()
|
||||
.skip(offset as usize)
|
||||
.take(page_size as usize)
|
||||
.collect();
|
||||
|
||||
// Build response items
|
||||
let mut data = Vec::new();
|
||||
@@ -889,7 +916,10 @@ async fn get_file_faces(
|
||||
file_uuid: file_uuid.clone(),
|
||||
frame_number: frame,
|
||||
timestamp_secs: Some(frame as f64 / fps),
|
||||
face_id: payload.get("face_id").and_then(|v| v.as_str()).map(|s| s.to_string()),
|
||||
face_id: payload
|
||||
.get("face_id")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.to_string()),
|
||||
trace_id: payload["trace_id"].as_i64().map(|t| t as i32),
|
||||
bbox: BBox {
|
||||
x: bbox["x"].as_f64().unwrap_or(0.0),
|
||||
@@ -1315,8 +1345,8 @@ async fn set_profile_from_face(
|
||||
Path(identity_uuid): Path<String>,
|
||||
Json(req): Json<SetProfileFromFaceRequest>,
|
||||
) -> Result<Json<ProfileImageResponse>, (StatusCode, Json<serde_json::Value>)> {
|
||||
use crate::core::db::schema;
|
||||
use crate::core::db::qdrant_db::QdrantDb;
|
||||
use crate::core::db::schema;
|
||||
use serde_json::json;
|
||||
let videos_table = schema::table_name("videos");
|
||||
|
||||
@@ -1341,13 +1371,16 @@ async fn set_profile_from_face(
|
||||
let row: Option<(i64, i32, i32, i32, i32, f64)> = if let Some(trace_id) = use_trace {
|
||||
let mut filter_conds = vec![
|
||||
json!({"key": "file_uuid", "match": {"value": req.file_uuid}}),
|
||||
json!({"key": "trace_id", "match": {"value": trace_id}})
|
||||
json!({"key": "trace_id", "match": {"value": trace_id}}),
|
||||
];
|
||||
if let Some(frame) = use_frame {
|
||||
filter_conds.push(json!({"key": "frame", "match": {"value": frame}}));
|
||||
}
|
||||
let face_filter = json!({"must": filter_conds});
|
||||
let points = qdrant.scroll_all_points("_faces", face_filter, 10).await.unwrap_or_default();
|
||||
let points = qdrant
|
||||
.scroll_all_points("_faces", face_filter, 10)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
points.first().map(|p| {
|
||||
let payload = &p["payload"];
|
||||
let bbox = &payload["bbox"];
|
||||
|
||||
Reference in New Issue
Block a user