feat: update core API, database layer, and worker modules

- Remove unused imports (n8n_search, universal_search, Client, Arc, etc.)
- Update API endpoints for identity, face recognition, search
- Fix postgres_db.rs search_videos parent_uuid column
- Add snapshot API and identity agent API
- Clean up backup files (.bak, .bak2)
This commit is contained in:
Warren
2026-04-30 15:07:02 +08:00
parent 8f2208dd63
commit 2b23d1cfbd
148 changed files with 8553 additions and 48637 deletions

View File

@@ -4,7 +4,7 @@ use serde::{de::DeserializeOwned, Serialize};
use std::sync::Arc;
use tokio::sync::RwLock;
use crate::core::config::{cache as cache_config, REDIS_KEY_PREFIX};
use crate::core::config::{cache as cache_config, snapshot as snapshot_config, REDIS_KEY_PREFIX};
use crate::core::db::RedisClient;
pub struct RedisCache {
@@ -133,6 +133,135 @@ impl RedisCache {
pub async fn invalidate_videos_list(&self) -> Result<u64> {
self.invalidate_pattern("videos:*").await
}
// --- Snapshot Cache Methods ---
pub async fn snapshot_hits_key(file_uuid: &str) -> String {
format!("snapshot:hits:{}", file_uuid)
}
pub async fn snapshot_status_key(file_uuid: &str) -> String {
format!("snapshot:status:{}", file_uuid)
}
pub async fn snapshot_last_access_key(file_uuid: &str) -> String {
format!("snapshot:last_access:{}", file_uuid)
}
pub async fn snapshot_migrate_hint_key(file_uuid: &str) -> String {
format!("snapshot:migrate_hint:{}", file_uuid)
}
pub async fn increment_snapshot_hits(&self, file_uuid: &str) -> Result<u64> {
let client = self.client.read().await;
let mut conn = client.get_conn_internal().await?;
let key = Self::snapshot_hits_key(file_uuid).await;
let new_count: u64 = redis::cmd("INCR").arg(&key).query_async(&mut conn).await?;
let _: () = redis::cmd("EXPIRE")
.arg(&key)
.arg(*snapshot_config::WARM_TTL_SECS)
.query_async(&mut conn)
.await?;
Ok(new_count)
}
pub async fn get_snapshot_hits(&self, file_uuid: &str) -> Result<u64> {
let client = self.client.read().await;
let mut conn = client.get_conn_internal().await?;
let key = Self::snapshot_hits_key(file_uuid).await;
let count: Option<u64> = conn.get(&key).await?;
Ok(count.unwrap_or(0))
}
pub async fn update_last_access(&self, file_uuid: &str) -> Result<()> {
let client = self.client.read().await;
let mut conn = client.get_conn_internal().await?;
let key = Self::snapshot_last_access_key(file_uuid).await;
let now: i64 = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs() as i64;
let _: String = conn
.set_ex(&key, now, *snapshot_config::WARM_TTL_SECS)
.await?;
Ok(())
}
pub async fn set_snapshot_status(
&self,
file_uuid: &str,
status: &str,
progress: Option<f32>,
) -> Result<()> {
let client = self.client.read().await;
let mut conn = client.get_conn_internal().await?;
let key = Self::snapshot_status_key(file_uuid).await;
let payload = serde_json::json!({
"status": status,
"progress": progress,
});
let json = serde_json::to_string(&payload)?;
let ttl = if status == "generating" {
*crate::core::config::snapshot::GENERATING_TIMEOUT_SECS
} else {
*snapshot_config::WARM_TTL_SECS
};
let _: String = conn.set_ex(&key, json, ttl).await?;
Ok(())
}
pub async fn get_snapshot_status(&self, file_uuid: &str) -> Result<serde_json::Value> {
let client = self.client.read().await;
let mut conn = client.get_conn_internal().await?;
let key = Self::snapshot_status_key(file_uuid).await;
let value: Option<String> = conn.get(&key).await?;
match value {
Some(json) => Ok(serde_json::from_str(&json)?),
None => Ok(serde_json::json!({
"status": "cold",
"progress": null,
})),
}
}
pub async fn clear_snapshot_status(&self, file_uuid: &str) -> Result<()> {
let client = self.client.read().await;
let mut conn = client.get_conn_internal().await?;
let key = Self::snapshot_status_key(file_uuid).await;
let _: () = conn.del(&key).await?;
Ok(())
}
pub async fn set_migrate_hint(
&self,
file_uuid: &str,
parent_uuid: &str,
count: u64,
) -> Result<()> {
let client = self.client.read().await;
let mut conn = client.get_conn_internal().await?;
let key = Self::snapshot_migrate_hint_key(file_uuid).await;
let payload = serde_json::json!({
"parent_uuid": parent_uuid,
"count": count,
});
let json = serde_json::to_string(&payload)?;
let _: String = conn
.set_ex(&key, json, *snapshot_config::WARM_TTL_SECS)
.await?;
Ok(())
}
pub async fn get_migrate_hint(&self, file_uuid: &str) -> Result<Option<serde_json::Value>> {
let client = self.client.read().await;
let mut conn = client.get_conn_internal().await?;
let key = Self::snapshot_migrate_hint_key(file_uuid).await;
let value: Option<String> = conn.get(&key).await?;
match value {
Some(json) => Ok(Some(serde_json::from_str(&json)?)),
None => Ok(None),
}
}
}
impl Clone for RedisCache {