refactor: deduplicate filter plugins, extract helpers across codebase
Bug fixes: - client: add error field to ApiResponse to avoid swallowing server errors - args/config: fix list_format default mismatch (5 vs 7 columns) - client: url-encode size param in set_item_size Dedup - filter plugins: - Extract count_option() and pattern_option() helpers, replace 7 identical options() - Add #[derive(Clone)] to all filter structs; remove verbose clone_box() impls - Simplify FilterChain clone() and impl Clone for Box<dyn FilterPlugin> - Add filter_clone_box! macro for future use - Fix doctest example missing clone_box Dedup - server API: - Extract spawn_body_reader() with LimitBehavior enum for body streaming - Extract check_binary_content() helper - Extract stream_with_offset_and_length() helper - Extract generate_status() helper in status.rs - Extract append_query_params() helper in client.rs Dedup - other: - Extract yaml_value_to_string() in meta_plugin/mod.rs - Extract item_from_row() in db.rs - Delete unused DisplayListItem struct Misc: - Remove duplicate doc comment in compression_service.rs
This commit is contained in:
33
src/db.rs
33
src/db.rs
@@ -2,7 +2,7 @@ use anyhow::{Context, Error, Result, anyhow};
|
||||
use chrono::prelude::*;
|
||||
use lazy_static::lazy_static;
|
||||
use log::*;
|
||||
use rusqlite::{Connection, OpenFlags, params};
|
||||
use rusqlite::{Connection, OpenFlags, Row, params};
|
||||
use rusqlite_migration::{M, Migrations};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
@@ -112,6 +112,17 @@ pub struct Item {
|
||||
pub compression: String,
|
||||
}
|
||||
|
||||
fn item_from_row(row: &Row) -> Result<Item> {
|
||||
Ok(Item {
|
||||
id: row.get(0)?,
|
||||
ts: row.get(1)?,
|
||||
uncompressed_size: row.get(2)?,
|
||||
compressed_size: row.get(3)?,
|
||||
closed: row.get(4)?,
|
||||
compression: row.get(5)?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Represents a tag associated with an item.
|
||||
///
|
||||
/// Defines the relationship between items and tags in a many-to-many structure.
|
||||
@@ -852,15 +863,7 @@ pub fn query_all_items(conn: &Connection) -> Result<Vec<Item>> {
|
||||
let mut items = Vec::new();
|
||||
|
||||
while let Some(row) = rows.next()? {
|
||||
let item = Item {
|
||||
id: row.get(0)?,
|
||||
ts: row.get(1)?,
|
||||
uncompressed_size: row.get(2)?,
|
||||
compressed_size: row.get(3)?,
|
||||
closed: row.get(4)?,
|
||||
compression: row.get(5)?,
|
||||
};
|
||||
items.push(item);
|
||||
items.push(item_from_row(row)?);
|
||||
}
|
||||
|
||||
Ok(items)
|
||||
@@ -931,15 +934,7 @@ pub fn query_tagged_items<'a>(conn: &'a Connection, tags: &'a Vec<String>) -> Re
|
||||
let mut items = Vec::new();
|
||||
|
||||
while let Some(row) = rows.next()? {
|
||||
let item = Item {
|
||||
id: row.get(0)?,
|
||||
ts: row.get(1)?,
|
||||
uncompressed_size: row.get(2)?,
|
||||
compressed_size: row.get(3)?,
|
||||
closed: row.get(4)?,
|
||||
compression: row.get(5)?,
|
||||
};
|
||||
items.push(item);
|
||||
items.push(item_from_row(row)?);
|
||||
}
|
||||
|
||||
Ok(items)
|
||||
|
||||
Reference in New Issue
Block a user