fix(sync): fix issue where the webdav tasks weren't inserting source metadata into db
This commit is contained in:
parent
9ba62bb16e
commit
96ea060450
|
|
@ -11,8 +11,8 @@ impl Database {
|
||||||
pub async fn create_document(&self, document: Document) -> Result<Document> {
|
pub async fn create_document(&self, document: Document) -> Result<Document> {
|
||||||
let query_str = format!(
|
let query_str = format!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO documents (id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, ocr_confidence, ocr_word_count, ocr_processing_time_ms, ocr_status, ocr_error, ocr_completed_at, ocr_retry_count, ocr_failure_reason, tags, created_at, updated_at, user_id, file_hash, original_created_at, original_modified_at, source_metadata)
|
INSERT INTO documents (id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, ocr_confidence, ocr_word_count, ocr_processing_time_ms, ocr_status, ocr_error, ocr_completed_at, ocr_retry_count, ocr_failure_reason, tags, created_at, updated_at, user_id, file_hash, original_created_at, original_modified_at, source_path, source_type, source_id, file_permissions, file_owner, file_group, source_metadata)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30)
|
||||||
RETURNING {}
|
RETURNING {}
|
||||||
"#,
|
"#,
|
||||||
DOCUMENT_FIELDS
|
DOCUMENT_FIELDS
|
||||||
|
|
@ -42,6 +42,12 @@ impl Database {
|
||||||
.bind(&document.file_hash)
|
.bind(&document.file_hash)
|
||||||
.bind(document.original_created_at)
|
.bind(document.original_created_at)
|
||||||
.bind(document.original_modified_at)
|
.bind(document.original_modified_at)
|
||||||
|
.bind(&document.source_path)
|
||||||
|
.bind(&document.source_type)
|
||||||
|
.bind(document.source_id)
|
||||||
|
.bind(document.file_permissions)
|
||||||
|
.bind(&document.file_owner)
|
||||||
|
.bind(&document.file_group)
|
||||||
.bind(&document.source_metadata)
|
.bind(&document.source_metadata)
|
||||||
.fetch_one(&self.pool)
|
.fetch_one(&self.pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -179,7 +185,7 @@ impl Database {
|
||||||
r#"
|
r#"
|
||||||
SELECT {}
|
SELECT {}
|
||||||
FROM documents
|
FROM documents
|
||||||
WHERE user_id = $1 AND source_metadata->>'source_id' = $2
|
WHERE user_id = $1 AND source_id = $2
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT $3
|
LIMIT $3
|
||||||
"#,
|
"#,
|
||||||
|
|
@ -188,7 +194,7 @@ impl Database {
|
||||||
|
|
||||||
let rows = sqlx::query(&query_str)
|
let rows = sqlx::query(&query_str)
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
.bind(source_id.to_string())
|
.bind(source_id)
|
||||||
.bind(limit)
|
.bind(limit)
|
||||||
.fetch_all(&self.pool)
|
.fetch_all(&self.pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
||||||
|
|
@ -188,11 +188,11 @@ impl Database {
|
||||||
COUNT(*) as total_documents,
|
COUNT(*) as total_documents,
|
||||||
COUNT(CASE WHEN ocr_text IS NOT NULL THEN 1 END) as total_documents_ocr
|
COUNT(CASE WHEN ocr_text IS NOT NULL THEN 1 END) as total_documents_ocr
|
||||||
FROM documents
|
FROM documents
|
||||||
WHERE user_id = $1 AND source_metadata->>'source_id' = $2
|
WHERE user_id = $1 AND source_id = $2
|
||||||
"#
|
"#
|
||||||
)
|
)
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
.bind(source_id.to_string())
|
.bind(source_id)
|
||||||
.fetch_one(&self.pool)
|
.fetch_one(&self.pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
@ -205,27 +205,25 @@ impl Database {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let source_id_strings: Vec<String> = source_ids.iter().map(|id| id.to_string()).collect();
|
|
||||||
|
|
||||||
let rows = sqlx::query(
|
let rows = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT
|
SELECT
|
||||||
source_metadata->>'source_id' as source_id_str,
|
source_id,
|
||||||
COUNT(*) as total_documents,
|
COUNT(*) as total_documents,
|
||||||
COUNT(CASE WHEN ocr_text IS NOT NULL THEN 1 END) as total_documents_ocr
|
COUNT(CASE WHEN ocr_text IS NOT NULL THEN 1 END) as total_documents_ocr
|
||||||
FROM documents
|
FROM documents
|
||||||
WHERE user_id = $1 AND source_metadata->>'source_id' = ANY($2)
|
WHERE user_id = $1 AND source_id = ANY($2)
|
||||||
GROUP BY source_metadata->>'source_id'
|
GROUP BY source_id
|
||||||
"#
|
"#
|
||||||
)
|
)
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
.bind(&source_id_strings)
|
.bind(source_ids)
|
||||||
.fetch_all(&self.pool)
|
.fetch_all(&self.pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(rows.into_iter().map(|row| {
|
Ok(rows.into_iter().map(|row| {
|
||||||
let source_id_str: String = row.get("source_id_str");
|
let source_id: Uuid = row.get("source_id");
|
||||||
let source_id = Uuid::parse_str(&source_id_str).unwrap_or_default();
|
|
||||||
let total_documents: i64 = row.get("total_documents");
|
let total_documents: i64 = row.get("total_documents");
|
||||||
let total_documents_ocr: i64 = row.get("total_documents_ocr");
|
let total_documents_ocr: i64 = row.get("total_documents_ocr");
|
||||||
(source_id, total_documents, total_documents_ocr)
|
(source_id, total_documents, total_documents_ocr)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue