mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 01:40:21 +08:00
refactor: 抽离 AI pipeline 与调度共享能力逻辑
This commit is contained in:
@@ -67,8 +67,8 @@ impl GeminiFileMappingReadRepository for InMemoryGeminiFileMappingRepository {
|
||||
.collect::<Vec<_>>();
|
||||
items.sort_by(|left, right| {
|
||||
right
|
||||
.created_at_unix_secs
|
||||
.cmp(&left.created_at_unix_secs)
|
||||
.created_at_unix_ms
|
||||
.cmp(&left.created_at_unix_ms)
|
||||
.then_with(|| left.file_name.cmp(&right.file_name))
|
||||
});
|
||||
let total = items.len();
|
||||
@@ -127,9 +127,9 @@ impl GeminiFileMappingWriteRepository for InMemoryGeminiFileMappingRepository {
|
||||
.by_file
|
||||
.write()
|
||||
.expect("gemini mapping repository lock");
|
||||
let created_at_unix_secs = guard
|
||||
let created_at_unix_ms = guard
|
||||
.get(&record.file_name)
|
||||
.map(|existing| existing.created_at_unix_secs)
|
||||
.map(|existing| existing.created_at_unix_ms)
|
||||
.unwrap_or_else(current_unix_secs);
|
||||
let mapping = StoredGeminiFileMapping {
|
||||
id: record.id.clone(),
|
||||
@@ -139,7 +139,7 @@ impl GeminiFileMappingWriteRepository for InMemoryGeminiFileMappingRepository {
|
||||
display_name: record.display_name.clone(),
|
||||
mime_type: record.mime_type.clone(),
|
||||
source_hash: record.source_hash.clone(),
|
||||
created_at_unix_secs,
|
||||
created_at_unix_ms,
|
||||
expires_at_unix_secs: record.expires_at_unix_secs,
|
||||
};
|
||||
guard.insert(record.file_name.clone(), mapping.clone());
|
||||
@@ -242,7 +242,7 @@ mod tests {
|
||||
let first = repo.upsert(sample_record("id-1", "files/same")).await?;
|
||||
let replaced = repo.upsert(sample_record("id-2", "files/same")).await?;
|
||||
|
||||
assert_eq!(replaced.created_at_unix_secs, first.created_at_unix_secs);
|
||||
assert_eq!(replaced.created_at_unix_ms, first.created_at_unix_ms);
|
||||
assert_eq!(replaced.id, "id-2");
|
||||
Ok(())
|
||||
}
|
||||
@@ -303,7 +303,7 @@ mod tests {
|
||||
id: &str,
|
||||
file_name: &str,
|
||||
mime_type: &str,
|
||||
created_at_unix_secs: u64,
|
||||
created_at_unix_ms: u64,
|
||||
expires_at_unix_secs: u64,
|
||||
) -> crate::repository::gemini_file_mappings::StoredGeminiFileMapping {
|
||||
crate::repository::gemini_file_mappings::StoredGeminiFileMapping {
|
||||
@@ -314,7 +314,7 @@ mod tests {
|
||||
display_name: Some(format!("display-{id}")),
|
||||
mime_type: (!mime_type.is_empty()).then(|| mime_type.to_string()),
|
||||
source_hash: Some(format!("hash-{id}")),
|
||||
created_at_unix_secs,
|
||||
created_at_unix_ms,
|
||||
expires_at_unix_secs,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ impl SqlxGeminiFileMappingRepository {
|
||||
display_name: row.try_get("display_name").ok().flatten(),
|
||||
mime_type: row.try_get("mime_type").ok().flatten(),
|
||||
source_hash: row.try_get("source_hash").ok().flatten(),
|
||||
created_at_unix_secs: u64::try_from(
|
||||
row.try_get::<i64, _>("created_at_unix_secs")
|
||||
created_at_unix_ms: u64::try_from(
|
||||
row.try_get::<i64, _>("created_at_unix_ms")
|
||||
.map_postgres_err()?,
|
||||
)
|
||||
.map_err(|_| {
|
||||
@@ -65,7 +65,7 @@ SELECT
|
||||
display_name,
|
||||
mime_type,
|
||||
source_hash,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_secs,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_ms,
|
||||
EXTRACT(EPOCH FROM expires_at)::bigint AS expires_at_unix_secs
|
||||
FROM gemini_file_mappings
|
||||
WHERE file_name = $1
|
||||
@@ -204,7 +204,7 @@ RETURNING
|
||||
display_name,
|
||||
mime_type,
|
||||
source_hash,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_secs,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_ms,
|
||||
EXTRACT(EPOCH FROM expires_at)::bigint AS expires_at_unix_secs
|
||||
"#,
|
||||
)
|
||||
@@ -254,7 +254,7 @@ RETURNING
|
||||
display_name,
|
||||
mime_type,
|
||||
source_hash,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_secs,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_ms,
|
||||
EXTRACT(EPOCH FROM expires_at)::bigint AS expires_at_unix_secs
|
||||
"#,
|
||||
)
|
||||
@@ -304,7 +304,7 @@ SELECT
|
||||
display_name,
|
||||
mime_type,
|
||||
source_hash,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_secs,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_ms,
|
||||
EXTRACT(EPOCH FROM expires_at)::bigint AS expires_at_unix_secs
|
||||
FROM gemini_file_mappings
|
||||
WHERE 1=1
|
||||
|
||||
@@ -38,7 +38,7 @@ pub struct StoredGeminiFileMapping {
|
||||
pub display_name: Option<String>,
|
||||
pub mime_type: Option<String>,
|
||||
pub source_hash: Option<String>,
|
||||
pub created_at_unix_secs: u64,
|
||||
pub created_at_unix_ms: u64,
|
||||
pub expires_at_unix_secs: u64,
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ impl StoredGeminiFileMapping {
|
||||
id: String,
|
||||
file_name: String,
|
||||
key_id: String,
|
||||
created_at_unix_secs: i64,
|
||||
created_at_unix_ms: i64,
|
||||
expires_at_unix_secs: i64,
|
||||
) -> Result<Self, crate::DataLayerError> {
|
||||
if file_name.trim().is_empty() {
|
||||
@@ -60,9 +60,9 @@ impl StoredGeminiFileMapping {
|
||||
"gemini_file_mappings.key_id is empty".to_string(),
|
||||
));
|
||||
}
|
||||
let created_at_unix_secs = u64::try_from(created_at_unix_secs).map_err(|_| {
|
||||
let created_at_unix_ms = u64::try_from(created_at_unix_ms).map_err(|_| {
|
||||
crate::DataLayerError::UnexpectedValue(format!(
|
||||
"invalid gemini_file_mappings.created_at: {created_at_unix_secs}"
|
||||
"invalid gemini_file_mappings.created_at: {created_at_unix_ms}"
|
||||
))
|
||||
})?;
|
||||
let expires_at_unix_secs = u64::try_from(expires_at_unix_secs).map_err(|_| {
|
||||
@@ -78,7 +78,7 @@ impl StoredGeminiFileMapping {
|
||||
display_name: None,
|
||||
mime_type: None,
|
||||
source_hash: None,
|
||||
created_at_unix_secs,
|
||||
created_at_unix_ms,
|
||||
expires_at_unix_secs,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user