refactor: remove transaction usage from save_item method
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -222,20 +222,18 @@ impl ItemService {
|
|||||||
debug!("ITEM_SERVICE: Using compression type: {:?}", compression_type);
|
debug!("ITEM_SERVICE: Using compression type: {:?}", compression_type);
|
||||||
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 new item with id: {}", item_id);
|
debug!("ITEM_SERVICE: Created new item with id: {}", item_id);
|
||||||
db::set_item_tags(&tx, item.clone(), tags)?;
|
db::set_item_tags(conn, item.clone(), tags)?;
|
||||||
debug!("ITEM_SERVICE: Set tags for item {}", item_id);
|
debug!("ITEM_SERVICE: Set tags for item {}", item_id);
|
||||||
let item_meta = self.meta_service.collect_initial_meta();
|
let item_meta = self.meta_service.collect_initial_meta();
|
||||||
debug!("ITEM_SERVICE: Collected {} initial meta entries", item_meta.len());
|
debug!("ITEM_SERVICE: Collected {} initial meta entries", item_meta.len());
|
||||||
for (k, v) in item_meta.iter() {
|
for (k, v) in item_meta.iter() {
|
||||||
db::add_meta(&tx, item_id, k, v)?;
|
db::add_meta(conn, item_id, k, v)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +263,7 @@ impl ItemService {
|
|||||||
|
|
||||||
let mut plugins = self.meta_service.get_plugins(cmd, settings);
|
let mut plugins = self.meta_service.get_plugins(cmd, settings);
|
||||||
debug!("ITEM_SERVICE: Got {} meta plugins", plugins.len());
|
debug!("ITEM_SERVICE: Got {} meta plugins", plugins.len());
|
||||||
self.meta_service.initialize_plugins(&mut plugins, &tx, item_id);
|
self.meta_service.initialize_plugins(&mut plugins, conn, item_id);
|
||||||
|
|
||||||
let mut item_path = self.data_path.clone();
|
let mut item_path = self.data_path.clone();
|
||||||
item_path.push(item_id.to_string());
|
item_path.push(item_id.to_string());
|
||||||
@@ -283,7 +281,7 @@ impl ItemService {
|
|||||||
|
|
||||||
total_bytes += n as i64;
|
total_bytes += n as i64;
|
||||||
item_out.write_all(&buffer[..n])?;
|
item_out.write_all(&buffer[..n])?;
|
||||||
self.meta_service.process_chunk(&mut plugins, &buffer[..n], &tx, item_id);
|
self.meta_service.process_chunk(&mut plugins, &buffer[..n], conn, item_id);
|
||||||
}
|
}
|
||||||
debug!("ITEM_SERVICE: Processed {} bytes total", total_bytes);
|
debug!("ITEM_SERVICE: Processed {} bytes total", total_bytes);
|
||||||
|
|
||||||
@@ -291,13 +289,12 @@ impl ItemService {
|
|||||||
drop(item_out);
|
drop(item_out);
|
||||||
|
|
||||||
debug!("ITEM_SERVICE: Finalizing meta plugins");
|
debug!("ITEM_SERVICE: Finalizing meta plugins");
|
||||||
self.meta_service.finalize_plugins(&mut plugins, &tx, item_id);
|
self.meta_service.finalize_plugins(&mut plugins, conn, item_id);
|
||||||
|
|
||||||
item.size = Some(total_bytes);
|
item.size = Some(total_bytes);
|
||||||
db::update_item(&tx, item.clone())?;
|
db::update_item(conn, item.clone())?;
|
||||||
|
|
||||||
tx.commit()?;
|
debug!("ITEM_SERVICE: Save completed successfully");
|
||||||
debug!("ITEM_SERVICE: Transaction committed successfully");
|
|
||||||
|
|
||||||
Ok(item_id)
|
Ok(item_id)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user