fix test
This commit is contained in:
parent
cbd5435e26
commit
27f5c435de
@ -162,6 +162,26 @@ impl OfflineRepository {
|
|||||||
|
|
||||||
let now = chrono::Utc::now().to_rfc3339();
|
let now = chrono::Utc::now().to_rfc3339();
|
||||||
|
|
||||||
|
// Temporarily disable foreign key constraints to avoid CASCADE DELETE issues
|
||||||
|
// when replacing stub parent items with their actual data
|
||||||
|
self.db_service.execute(Query::new("PRAGMA foreign_keys = OFF")).await
|
||||||
|
.map_err(|e| RepoError::Database { message: e })?;
|
||||||
|
|
||||||
|
// Ensure we re-enable foreign keys even if an error occurs
|
||||||
|
let result = self.save_to_cache_impl(parent_id, items, &now).await;
|
||||||
|
|
||||||
|
// Re-enable foreign key constraints
|
||||||
|
let _ = self.db_service.execute(Query::new("PRAGMA foreign_keys = ON")).await;
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn save_to_cache_impl(
|
||||||
|
&self,
|
||||||
|
parent_id: &str,
|
||||||
|
items: &[MediaItem],
|
||||||
|
now: &str,
|
||||||
|
) -> Result<usize, RepoError> {
|
||||||
// Collect all unique parent IDs referenced by items being saved
|
// Collect all unique parent IDs referenced by items being saved
|
||||||
let mut parent_ids = std::collections::HashSet::new();
|
let mut parent_ids = std::collections::HashSet::new();
|
||||||
parent_ids.insert(parent_id.to_string());
|
parent_ids.insert(parent_id.to_string());
|
||||||
@ -185,7 +205,7 @@ impl OfflineRepository {
|
|||||||
QueryParam::String(self.server_id.clone()),
|
QueryParam::String(self.server_id.clone()),
|
||||||
QueryParam::String("Parent".to_string()),
|
QueryParam::String("Parent".to_string()),
|
||||||
QueryParam::String("Folder".to_string()),
|
QueryParam::String("Folder".to_string()),
|
||||||
QueryParam::String(now.clone()),
|
QueryParam::String(now.to_string()),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -206,8 +226,6 @@ impl OfflineRepository {
|
|||||||
let backdrop_tags_json = item.backdrop_image_tags.as_ref()
|
let backdrop_tags_json = item.backdrop_image_tags.as_ref()
|
||||||
.map(|b| serde_json::to_string(b).unwrap_or_else(|_| "[]".to_string()));
|
.map(|b| serde_json::to_string(b).unwrap_or_else(|_| "[]".to_string()));
|
||||||
|
|
||||||
let now = chrono::Utc::now().to_rfc3339();
|
|
||||||
|
|
||||||
// Use INSERT OR REPLACE to upsert items
|
// Use INSERT OR REPLACE to upsert items
|
||||||
let query = Query::with_params(
|
let query = Query::with_params(
|
||||||
"INSERT OR REPLACE INTO items (
|
"INSERT OR REPLACE INTO items (
|
||||||
@ -315,7 +333,7 @@ impl OfflineRepository {
|
|||||||
Some(r) => QueryParam::String(r.clone()),
|
Some(r) => QueryParam::String(r.clone()),
|
||||||
None => QueryParam::Null,
|
None => QueryParam::Null,
|
||||||
},
|
},
|
||||||
QueryParam::String(now.clone()),
|
QueryParam::String(now.to_string()),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user