refactor: Simplify content streaming by consolidating filter parameters
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -206,14 +206,6 @@ impl AsyncItemService {
|
||||
// Get binary status using streaming approach
|
||||
let (_, _, is_binary) = self.get_item_content_info_streaming(
|
||||
item_id,
|
||||
head_bytes,
|
||||
head_words,
|
||||
head_lines,
|
||||
tail_bytes,
|
||||
tail_words,
|
||||
tail_lines,
|
||||
line_start,
|
||||
line_end,
|
||||
None
|
||||
).await?;
|
||||
is_binary
|
||||
@@ -233,15 +225,6 @@ impl AsyncItemService {
|
||||
item_service.get_item_content_info_streaming(
|
||||
&conn,
|
||||
item_id,
|
||||
head_bytes,
|
||||
head_words,
|
||||
head_lines,
|
||||
tail_bytes,
|
||||
tail_words,
|
||||
tail_lines,
|
||||
line_start,
|
||||
line_end,
|
||||
grep,
|
||||
None
|
||||
).map(|(reader, _, _)| reader)
|
||||
})
|
||||
@@ -342,15 +325,6 @@ impl AsyncItemService {
|
||||
item_service.get_item_content_info_streaming(
|
||||
&conn,
|
||||
item_id,
|
||||
head_bytes,
|
||||
head_words,
|
||||
head_lines,
|
||||
tail_bytes,
|
||||
tail_words,
|
||||
tail_lines,
|
||||
line_start,
|
||||
line_end,
|
||||
grep,
|
||||
None
|
||||
)
|
||||
})
|
||||
|
||||
@@ -151,9 +151,7 @@ impl ItemService {
|
||||
) -> Result<(Vec<u8>, String, bool), CoreError> {
|
||||
// Use streaming approach to handle all filtering options consistently
|
||||
let (mut reader, mime_type, is_binary) = self.get_item_content_info_streaming(
|
||||
conn, id, head_bytes, head_words, head_lines,
|
||||
tail_bytes, tail_words, tail_lines, line_start, line_end, grep,
|
||||
None
|
||||
conn, id, None
|
||||
)?;
|
||||
|
||||
// Read all the filtered content into a buffer
|
||||
@@ -163,46 +161,6 @@ impl ItemService {
|
||||
Ok((content, mime_type, is_binary))
|
||||
}
|
||||
|
||||
/// Helper method to create a filter chain from parameters
|
||||
fn create_filter_chain(
|
||||
&self,
|
||||
grep: Option<String>,
|
||||
head_bytes: Option<usize>,
|
||||
head_lines: Option<usize>,
|
||||
tail_bytes: Option<usize>,
|
||||
tail_lines: Option<usize>,
|
||||
filter: Option<String>,
|
||||
) -> Result<Option<filter_plugin::FilterChain>, CoreError> {
|
||||
// Build filter string from individual parameters (for backward compatibility)
|
||||
let mut filter_parts = Vec::new();
|
||||
if let Some(pattern) = grep {
|
||||
filter_parts.push(format!("grep('{}')", pattern.replace('\'', "\\'")));
|
||||
}
|
||||
if let Some(bytes) = head_bytes {
|
||||
filter_parts.push(format!("head_bytes({})", bytes));
|
||||
}
|
||||
if let Some(lines) = head_lines {
|
||||
filter_parts.push(format!("head_lines({})", lines));
|
||||
}
|
||||
if let Some(bytes) = tail_bytes {
|
||||
filter_parts.push(format!("tail_bytes({})", bytes));
|
||||
}
|
||||
if let Some(lines) = tail_lines {
|
||||
filter_parts.push(format!("tail_lines({})", lines));
|
||||
}
|
||||
|
||||
// Handle the provided filter string
|
||||
let filter_str = match (filter, filter_parts.is_empty()) {
|
||||
(Some(f), true) => Some(f),
|
||||
(Some(f), false) => Some(format!("{} | {}", f, filter_parts.join(" | "))),
|
||||
(None, true) => None,
|
||||
(None, false) => Some(filter_parts.join(" | ")),
|
||||
};
|
||||
|
||||
// Create filter chain
|
||||
self.filter_service.create_filter_chain(filter_str.as_deref())
|
||||
.map_err(|e| CoreError::InvalidInput(format!("Failed to create filter chain: {}", e)))
|
||||
}
|
||||
|
||||
/// Helper method to determine if content is binary
|
||||
fn is_content_binary(
|
||||
@@ -230,15 +188,6 @@ impl ItemService {
|
||||
&self,
|
||||
conn: &Connection,
|
||||
id: i64,
|
||||
head_bytes: Option<usize>,
|
||||
_head_words: Option<usize>,
|
||||
head_lines: Option<usize>,
|
||||
tail_bytes: Option<usize>,
|
||||
_tail_words: Option<usize>,
|
||||
tail_lines: Option<usize>,
|
||||
_line_start: Option<usize>,
|
||||
_line_end: Option<usize>,
|
||||
grep: Option<String>,
|
||||
filter: Option<String>,
|
||||
) -> Result<(Box<dyn Read + Send>, String, bool), CoreError> {
|
||||
let item_with_meta = self.get_item(conn, id)?;
|
||||
@@ -257,9 +206,8 @@ impl ItemService {
|
||||
)?;
|
||||
|
||||
// Create filter chain
|
||||
let filter_chain = self.create_filter_chain(
|
||||
grep, head_bytes, head_lines, tail_bytes, tail_lines, filter
|
||||
)?;
|
||||
let filter_chain = self.filter_service.create_filter_chain(filter.as_deref())
|
||||
.map_err(|e| CoreError::InvalidInput(format!("Failed to create filter chain: {}", e)))?;
|
||||
|
||||
// Wrap the reader with filtering
|
||||
let filtered_reader = Box::new(FilteringReader::new(reader, filter_chain));
|
||||
|
||||
Reference in New Issue
Block a user