feat: add finalization state tracking to meta plugins
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -161,6 +161,14 @@ pub trait MetaPlugin {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the plugin is already finalized
|
||||||
|
fn is_finalized(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the finalized state (only for plugins that can track this)
|
||||||
|
fn set_finalized(&mut self, _finalized: bool) {}
|
||||||
|
|
||||||
// Update the meta plugin with new data
|
// Update the meta plugin with new data
|
||||||
fn update(&mut self, _data: &[u8]) -> MetaPluginResponse {
|
fn update(&mut self, _data: &[u8]) -> MetaPluginResponse {
|
||||||
// Default implementation does nothing
|
// Default implementation does nothing
|
||||||
@@ -250,6 +258,11 @@ pub trait MetaPlugin {
|
|||||||
self.configure_outputs(outputs)?;
|
self.configure_outputs(outputs)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Method to downcast to concrete type (for checking finalization state)
|
||||||
|
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin> {
|
pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin> {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use crate::meta_plugin::{MetaPlugin, MetaPluginResponse};
|
|||||||
pub struct BinaryMetaPlugin {
|
pub struct BinaryMetaPlugin {
|
||||||
buffer: Vec<u8>,
|
buffer: Vec<u8>,
|
||||||
max_buffer_size: usize,
|
max_buffer_size: usize,
|
||||||
|
is_finalized: bool,
|
||||||
base: crate::meta_plugin::BaseMetaPlugin,
|
base: crate::meta_plugin::BaseMetaPlugin,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ impl BinaryMetaPlugin {
|
|||||||
BinaryMetaPlugin {
|
BinaryMetaPlugin {
|
||||||
buffer: Vec::new(),
|
buffer: Vec::new(),
|
||||||
max_buffer_size,
|
max_buffer_size,
|
||||||
|
is_finalized: false,
|
||||||
base,
|
base,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,8 +43,23 @@ impl BinaryMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MetaPlugin for BinaryMetaPlugin {
|
impl MetaPlugin for BinaryMetaPlugin {
|
||||||
|
fn is_finalized(&self) -> bool {
|
||||||
|
self.is_finalized
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_finalized(&mut self, finalized: bool) {
|
||||||
|
self.is_finalized = finalized;
|
||||||
|
}
|
||||||
|
|
||||||
fn update(&mut self, data: &[u8]) -> MetaPluginResponse {
|
fn update(&mut self, data: &[u8]) -> MetaPluginResponse {
|
||||||
|
// If already finalized, don't process more data
|
||||||
|
if self.is_finalized {
|
||||||
|
return MetaPluginResponse {
|
||||||
|
metadata: Vec::new(),
|
||||||
|
is_finalized: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate how much data we can still accept
|
// Calculate how much data we can still accept
|
||||||
let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len());
|
let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len());
|
||||||
if remaining_capacity > 0 {
|
if remaining_capacity > 0 {
|
||||||
@@ -67,6 +84,9 @@ impl MetaPlugin for BinaryMetaPlugin {
|
|||||||
) {
|
) {
|
||||||
metadata.push(meta_data);
|
metadata.push(meta_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark as finalized
|
||||||
|
self.is_finalized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_finalized = !metadata.is_empty();
|
let is_finalized = !metadata.is_empty();
|
||||||
@@ -77,6 +97,14 @@ impl MetaPlugin for BinaryMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn finalize(&mut self) -> MetaPluginResponse {
|
fn finalize(&mut self) -> MetaPluginResponse {
|
||||||
|
// If already finalized, don't process again
|
||||||
|
if self.is_finalized {
|
||||||
|
return MetaPluginResponse {
|
||||||
|
metadata: Vec::new(),
|
||||||
|
is_finalized: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let mut metadata = Vec::new();
|
let mut metadata = Vec::new();
|
||||||
|
|
||||||
// Save the binary detection result when finalizing
|
// Save the binary detection result when finalizing
|
||||||
@@ -91,6 +119,9 @@ impl MetaPlugin for BinaryMetaPlugin {
|
|||||||
) {
|
) {
|
||||||
metadata.push(meta_data);
|
metadata.push(meta_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark as finalized
|
||||||
|
self.is_finalized = true;
|
||||||
|
|
||||||
MetaPluginResponse {
|
MetaPluginResponse {
|
||||||
metadata,
|
metadata,
|
||||||
|
|||||||
@@ -125,15 +125,47 @@ impl MetaService {
|
|||||||
item_id: i64,
|
item_id: i64,
|
||||||
) {
|
) {
|
||||||
for meta_plugin in plugins.iter_mut() {
|
for meta_plugin in plugins.iter_mut() {
|
||||||
|
// Skip plugins that are already finalized
|
||||||
|
if let Some(internal_plugin) = meta_plugin.as_any_mut().downcast_mut::<crate::meta_plugin::BinaryMetaPlugin>() {
|
||||||
|
if internal_plugin.is_finalized() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add similar checks for other internal plugin types as needed
|
||||||
|
|
||||||
let response = meta_plugin.update(chunk);
|
let response = meta_plugin.update(chunk);
|
||||||
self.process_plugin_response(conn, item_id, meta_plugin, response);
|
self.process_plugin_response(conn, item_id, meta_plugin, response);
|
||||||
|
|
||||||
|
// Set finalized flag if response indicates finalization
|
||||||
|
if response.is_finalized {
|
||||||
|
if let Some(internal_plugin) = meta_plugin.as_any_mut().downcast_mut::<crate::meta_plugin::BinaryMetaPlugin>() {
|
||||||
|
internal_plugin.set_finalized(true);
|
||||||
|
}
|
||||||
|
// Add similar checks for other internal plugin types as needed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finalize_plugins(&self, plugins: &mut [Box<dyn MetaPlugin>], conn: &Connection, item_id: i64) {
|
pub fn finalize_plugins(&self, plugins: &mut [Box<dyn MetaPlugin>], conn: &Connection, item_id: i64) {
|
||||||
for meta_plugin in plugins.iter_mut() {
|
for meta_plugin in plugins.iter_mut() {
|
||||||
|
// Skip plugins that are already finalized
|
||||||
|
if let Some(internal_plugin) = meta_plugin.as_any_mut().downcast_mut::<crate::meta_plugin::BinaryMetaPlugin>() {
|
||||||
|
if internal_plugin.is_finalized() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add similar checks for other internal plugin types as needed
|
||||||
|
|
||||||
let response = meta_plugin.finalize();
|
let response = meta_plugin.finalize();
|
||||||
self.process_plugin_response(conn, item_id, meta_plugin, response);
|
self.process_plugin_response(conn, item_id, meta_plugin, response);
|
||||||
|
|
||||||
|
// Set finalized flag if response indicates finalization
|
||||||
|
if response.is_finalized {
|
||||||
|
if let Some(internal_plugin) = meta_plugin.as_any_mut().downcast_mut::<crate::meta_plugin::BinaryMetaPlugin>() {
|
||||||
|
internal_plugin.set_finalized(true);
|
||||||
|
}
|
||||||
|
// Add similar checks for other internal plugin types as needed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user