fix: fix async database locking and diff process order
Co-authored-by: aider (openai/andrew/openrouter/google/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -24,9 +24,10 @@ impl AsyncItemService {
|
||||
|
||||
pub async fn get_item(&self, id: i64) -> Result<ItemWithMeta, CoreError> {
|
||||
let data_path = self.data_path.clone();
|
||||
let conn = self.db.lock().await;
|
||||
let db = self.db.clone();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let conn = db.blocking_lock();
|
||||
let item_service = ItemService::new(data_path);
|
||||
item_service.get_item(&conn, id)
|
||||
})
|
||||
@@ -36,9 +37,10 @@ impl AsyncItemService {
|
||||
|
||||
pub async fn get_item_content(&self, id: i64) -> Result<ItemWithContent, CoreError> {
|
||||
let data_path = self.data_path.clone();
|
||||
let conn = self.db.lock().await;
|
||||
let db = self.db.clone();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let conn = db.blocking_lock();
|
||||
let item_service = ItemService::new(data_path);
|
||||
item_service.get_item_content(&conn, id)
|
||||
})
|
||||
@@ -53,9 +55,10 @@ impl AsyncItemService {
|
||||
meta: HashMap<String, String>,
|
||||
) -> Result<ItemWithMeta, CoreError> {
|
||||
let data_path = self.data_path.clone();
|
||||
let conn = self.db.lock().await;
|
||||
let db = self.db.clone();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let conn = db.blocking_lock();
|
||||
let item_service = ItemService::new(data_path);
|
||||
item_service.find_item(&conn, &ids, &tags, &meta)
|
||||
})
|
||||
@@ -69,9 +72,10 @@ impl AsyncItemService {
|
||||
meta: HashMap<String, String>,
|
||||
) -> Result<Vec<ItemWithMeta>, CoreError> {
|
||||
let data_path = self.data_path.clone();
|
||||
let conn = self.db.lock().await;
|
||||
let db = self.db.clone();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let conn = db.blocking_lock();
|
||||
let item_service = ItemService::new(data_path);
|
||||
item_service.list_items(&conn, &tags, &meta)
|
||||
})
|
||||
@@ -81,9 +85,10 @@ impl AsyncItemService {
|
||||
|
||||
pub async fn delete_item(&self, id: i64) -> Result<(), CoreError> {
|
||||
let data_path = self.data_path.clone();
|
||||
let mut conn = self.db.lock().await;
|
||||
let db = self.db.clone();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let mut conn = db.blocking_lock();
|
||||
let item_service = ItemService::new(data_path);
|
||||
item_service.delete_item(&mut conn, id)
|
||||
})
|
||||
@@ -98,9 +103,10 @@ impl AsyncItemService {
|
||||
metadata: HashMap<String, String>,
|
||||
) -> Result<ItemWithMeta, CoreError> {
|
||||
let data_path = self.data_path.clone();
|
||||
let mut conn = self.db.lock().await;
|
||||
let db = self.db.clone();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let mut conn = db.blocking_lock();
|
||||
let item_service = ItemService::new(data_path);
|
||||
item_service.save_item_from_mcp(&content, &tags, &metadata, &mut conn)
|
||||
})
|
||||
|
||||
@@ -383,7 +383,10 @@ pub fn mode_diff(
|
||||
|
||||
log::debug!("MAIN: Done waiting on input-writer threads.");
|
||||
|
||||
// Now that all input has been sent and input pipes will be closed by threads exiting,
|
||||
// Now that all input has been sent, the diff process will run to completion.
|
||||
// We can read its output. This will block until the process is finished.
|
||||
let (stdout_capture_result, stderr_capture_result) = execute_diff_command(&mut child_process)?;
|
||||
|
||||
// wait for the diff child process to terminate.
|
||||
log::debug!("MAIN: Waiting for diff child process to finish...");
|
||||
let diff_status = child_process
|
||||
@@ -394,7 +397,6 @@ pub fn mode_diff(
|
||||
diff_status
|
||||
);
|
||||
|
||||
let (stdout_capture_result, stderr_capture_result) = execute_diff_command(&mut child_process)?;
|
||||
handle_diff_output(diff_status, stdout_capture_result, stderr_capture_result)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user