refactor: remove database transactions from item service
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -197,10 +197,8 @@ impl ItemService {
|
|||||||
item_path.push(id.to_string());
|
item_path.push(id.to_string());
|
||||||
debug!("ITEM_SERVICE: Deleting file at path: {:?}", item_path);
|
debug!("ITEM_SERVICE: Deleting file at path: {:?}", item_path);
|
||||||
|
|
||||||
let tx = conn.transaction()?;
|
db::delete_item(conn, item)?;
|
||||||
db::delete_item(&tx, item)?;
|
|
||||||
fs::remove_file(&item_path).or_else(|e| if e.kind() == std::io::ErrorKind::NotFound { Ok(()) } else { Err(e) })?;
|
fs::remove_file(&item_path).or_else(|e| if e.kind() == std::io::ErrorKind::NotFound { Ok(()) } else { Err(e) })?;
|
||||||
tx.commit()?;
|
|
||||||
debug!("ITEM_SERVICE: Successfully deleted item {}", id);
|
debug!("ITEM_SERVICE: Successfully deleted item {}", id);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -316,24 +314,23 @@ impl ItemService {
|
|||||||
let compression_type = CompressionType::LZ4;
|
let compression_type = CompressionType::LZ4;
|
||||||
let compression_engine = get_compression_engine(compression_type.clone())?;
|
let compression_engine = get_compression_engine(compression_type.clone())?;
|
||||||
|
|
||||||
let tx = conn.transaction()?;
|
|
||||||
let item_id;
|
let item_id;
|
||||||
let mut item;
|
let mut item;
|
||||||
|
|
||||||
{
|
{
|
||||||
item = db::create_item(&tx, compression_type.clone())?;
|
item = db::create_item(conn, compression_type.clone())?;
|
||||||
item_id = item.id.unwrap();
|
item_id = item.id.unwrap();
|
||||||
debug!("ITEM_SERVICE: Created MCP item with id: {}", item_id);
|
debug!("ITEM_SERVICE: Created MCP item with id: {}", item_id);
|
||||||
|
|
||||||
// Add tags
|
// Add tags
|
||||||
for tag in tags {
|
for tag in tags {
|
||||||
db::add_tag(&tx, item_id, tag)?;
|
db::add_tag(conn, item_id, tag)?;
|
||||||
}
|
}
|
||||||
debug!("ITEM_SERVICE: Added {} tags to MCP item", tags.len());
|
debug!("ITEM_SERVICE: Added {} tags to MCP item", tags.len());
|
||||||
|
|
||||||
// Add custom metadata
|
// Add custom metadata
|
||||||
for (key, value) in metadata {
|
for (key, value) in metadata {
|
||||||
db::add_meta(&tx, item_id, key, value)?;
|
db::add_meta(conn, item_id, key, value)?;
|
||||||
}
|
}
|
||||||
debug!("ITEM_SERVICE: Added {} custom metadata entries to MCP item", metadata.len());
|
debug!("ITEM_SERVICE: Added {} custom metadata entries to MCP item", metadata.len());
|
||||||
}
|
}
|
||||||
@@ -362,17 +359,16 @@ impl ItemService {
|
|||||||
debug!("ITEM_SERVICE: Created {} meta plugins for MCP item", plugins.len());
|
debug!("ITEM_SERVICE: Created {} meta plugins for MCP item", plugins.len());
|
||||||
|
|
||||||
self.meta_service
|
self.meta_service
|
||||||
.initialize_plugins(&mut plugins, &tx, item_id);
|
.initialize_plugins(&mut plugins, conn, item_id);
|
||||||
self.meta_service
|
self.meta_service
|
||||||
.process_chunk(&mut plugins, content, &tx, item_id);
|
.process_chunk(&mut plugins, content, conn, item_id);
|
||||||
self.meta_service.finalize_plugins(&mut plugins, &tx, item_id);
|
self.meta_service.finalize_plugins(&mut plugins, conn, item_id);
|
||||||
debug!("ITEM_SERVICE: Processed MCP item through meta plugins");
|
debug!("ITEM_SERVICE: Processed MCP item through meta plugins");
|
||||||
|
|
||||||
item.size = Some(content.len() as i64);
|
item.size = Some(content.len() as i64);
|
||||||
db::update_item(&tx, item.clone())?;
|
db::update_item(conn, item.clone())?;
|
||||||
|
|
||||||
tx.commit()?;
|
debug!("ITEM_SERVICE: MCP item saved successfully");
|
||||||
debug!("ITEM_SERVICE: MCP item transaction committed successfully");
|
|
||||||
|
|
||||||
self.get_item(conn, item_id)
|
self.get_item(conn, item_id)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user