refactor: reduce code duplication in filter and item services
Co-authored-by: aider (openai/andrew/openrouter/mistralai/mistral-medium-3.1) <aider@aider.chat>
This commit is contained in:
@@ -361,15 +361,9 @@ impl AsyncItemService {
|
||||
tags: Vec<String>,
|
||||
meta: HashMap<String, String>,
|
||||
) -> Result<ItemWithMeta, CoreError> {
|
||||
let db = self.db.clone();
|
||||
let item_service = self.item_service.clone();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let conn = db.blocking_lock();
|
||||
item_service.find_item(&conn, &ids, &tags, &meta)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
self.execute_blocking(|conn, item_service| {
|
||||
item_service.find_item(conn, &ids, &tags, &meta)
|
||||
}).await
|
||||
}
|
||||
|
||||
pub async fn list_items(
|
||||
@@ -377,27 +371,15 @@ impl AsyncItemService {
|
||||
tags: Vec<String>,
|
||||
meta: HashMap<String, String>,
|
||||
) -> Result<Vec<ItemWithMeta>, CoreError> {
|
||||
let db = self.db.clone();
|
||||
let item_service = self.item_service.clone();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let conn = db.blocking_lock();
|
||||
item_service.list_items(&conn, &tags, &meta)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
self.execute_blocking(|conn, item_service| {
|
||||
item_service.list_items(conn, &tags, &meta)
|
||||
}).await
|
||||
}
|
||||
|
||||
pub async fn delete_item(&self, id: i64) -> Result<(), CoreError> {
|
||||
let db = self.db.clone();
|
||||
let item_service = self.item_service.clone();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let mut conn = db.blocking_lock();
|
||||
item_service.delete_item(&mut conn, id)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
self.execute_blocking_mut(|conn, item_service| {
|
||||
item_service.delete_item(conn, id)
|
||||
}).await
|
||||
}
|
||||
|
||||
pub async fn save_item_from_mcp(
|
||||
|
||||
Reference in New Issue
Block a user