refactor: remove connection storage from plugin structs and pass as argument
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -10,7 +10,6 @@ pub struct DigestSha256MetaPlugin {
|
||||
hasher: Sha256,
|
||||
meta_name: String,
|
||||
item_id: Option<i64>,
|
||||
conn: Option<*mut Connection>,
|
||||
output_names: std::collections::HashMap<String, String>,
|
||||
}
|
||||
|
||||
@@ -20,7 +19,6 @@ impl DigestSha256MetaPlugin {
|
||||
hasher: Sha256::new(),
|
||||
meta_name: "digest_sha256".to_string(),
|
||||
item_id: None,
|
||||
conn: None,
|
||||
output_names: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
@@ -31,29 +29,24 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||
fn initialize(&mut self, _conn: &Connection, item_id: i64) -> Result<()> {
|
||||
self.item_id = Some(item_id);
|
||||
// Store raw pointer to connection - unsafe but necessary for this design
|
||||
self.conn = Some(conn as *const _ as *mut Connection);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
if let (Some(conn), Some(item_id)) = (self.conn, self.item_id) {
|
||||
// Convert raw pointer back to reference (unsafe)
|
||||
let conn_ref = unsafe { &*conn };
|
||||
|
||||
fn finalize(&mut self, conn: &Connection) -> Result<()> {
|
||||
if let Some(item_id) = self.item_id {
|
||||
// Finalize the hash
|
||||
let hash_result = self.hasher.finalize_reset();
|
||||
let hex_string = format!("{:x}", hash_result);
|
||||
|
||||
// Save the hash as metadata using central output handler
|
||||
let _ = output_metadata(conn_ref, item_id, &self.meta_name, hex_string, &self.output_names);
|
||||
let _ = output_metadata(conn, item_id, &self.meta_name, hex_string, &self.output_names);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8]) {
|
||||
fn update(&mut self, data: &[u8], _conn: &Connection) {
|
||||
self.hasher.update(data);
|
||||
}
|
||||
|
||||
@@ -100,11 +93,11 @@ impl MetaPlugin for ReadTimeMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
fn update(&mut self, _data: &[u8], _conn: &Connection) {
|
||||
if self.start_time.is_none() {
|
||||
self.start_time = Some(Instant::now());
|
||||
}
|
||||
@@ -137,11 +130,11 @@ impl MetaPlugin for ReadRateMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8]) {
|
||||
fn update(&mut self, data: &[u8], _conn: &Connection) {
|
||||
if self.start_time.is_none() {
|
||||
self.start_time = Some(Instant::now());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user