Fix cargo clippy warnings across the workspace
All checks were successful
dev release / build (push) Successful in 4m4s
All checks were successful
dev release / build (push) Successful in 4m4s
- Derive Default for Config instead of manually mirroring each sub-config's Default impl - Use std::io::Error::other instead of Error::new(ErrorKind::Other, ..) - Drop the unused mut on the store lock in full_reindex - Remove Store::dim, a field that was set once and never read - Use char_indices().enumerate() instead of a hand-rolled loop counter in split_by_chars, and is_multiple_of() for the chunk boundary check - Use strip_prefix instead of manual slicing in expand_home (cherry picked from commit b740af38e17d04bd83db93bbb0585ed5744a436e)
This commit is contained in:
parent
4bfcc694bd
commit
993dc4a525
4 changed files with 8 additions and 22 deletions
|
|
@ -81,10 +81,9 @@ fn split_by_chars(chunk: Chunk, max_chars: usize) -> Vec<Chunk> {
|
||||||
let text = &chunk.text;
|
let text = &chunk.text;
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
let mut seg_start = 0usize;
|
let mut seg_start = 0usize;
|
||||||
let mut count = 0usize;
|
|
||||||
|
|
||||||
for (byte_idx, _) in text.char_indices() {
|
for (count, (byte_idx, _)) in text.char_indices().enumerate() {
|
||||||
if count > 0 && count % max_chars == 0 {
|
if count > 0 && count.is_multiple_of(max_chars) {
|
||||||
result.push(Chunk {
|
result.push(Chunk {
|
||||||
text: text[seg_start..byte_idx].to_string(),
|
text: text[seg_start..byte_idx].to_string(),
|
||||||
start: chunk.start + seg_start,
|
start: chunk.start + seg_start,
|
||||||
|
|
@ -92,7 +91,6 @@ fn split_by_chars(chunk: Chunk, max_chars: usize) -> Vec<Chunk> {
|
||||||
});
|
});
|
||||||
seg_start = byte_idx;
|
seg_start = byte_idx;
|
||||||
}
|
}
|
||||||
count += 1;
|
|
||||||
}
|
}
|
||||||
if seg_start < text.len() {
|
if seg_start < text.len() {
|
||||||
result.push(Chunk {
|
result.push(Chunk {
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ impl Indexer {
|
||||||
pub fn full_reindex(&self) {
|
pub fn full_reindex(&self) {
|
||||||
eprintln!("breadmill: full reindex triggered");
|
eprintln!("breadmill: full reindex triggered");
|
||||||
{
|
{
|
||||||
let mut store = self.state.store.lock_recover();
|
let store = self.state.store.lock_recover();
|
||||||
// Clear all state
|
// Clear all state
|
||||||
let _ = store.conn.execute_batch("DELETE FROM chunks; DELETE FROM files;");
|
let _ = store.conn.execute_batch("DELETE FROM chunks; DELETE FROM files;");
|
||||||
let _ = store.index.reserve(4096);
|
let _ = store.index.reserve(4096);
|
||||||
|
|
@ -416,9 +416,9 @@ fn sha256_str(bytes: &[u8]) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_home(path: &str) -> PathBuf {
|
pub fn expand_home(path: &str) -> PathBuf {
|
||||||
if path.starts_with("~/") {
|
if let Some(rest) = path.strip_prefix("~/") {
|
||||||
let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".into());
|
let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".into());
|
||||||
PathBuf::from(home).join(&path[2..])
|
PathBuf::from(home).join(rest)
|
||||||
} else {
|
} else {
|
||||||
PathBuf::from(path)
|
PathBuf::from(path)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ use usearch::{Index, IndexOptions, MetricKind, ScalarKind, new_index};
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
pub conn: Connection,
|
pub conn: Connection,
|
||||||
pub index: Index,
|
pub index: Index,
|
||||||
pub dim: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// usearch::Index wraps a raw C++ pointer; access is serialized by the Mutex<Store>.
|
// usearch::Index wraps a raw C++ pointer; access is serialized by the Mutex<Store>.
|
||||||
|
|
@ -87,7 +86,7 @@ impl Store {
|
||||||
index.reserve(4096).map_err(|e| e.to_string())?;
|
index.reserve(4096).map_err(|e| e.to_string())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self { conn, index, dim })
|
Ok(Self { conn, index })
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- file state ---------------------------------------------------------
|
// ---- file state ---------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ pub fn socket_path() -> PathBuf {
|
||||||
|
|
||||||
// ---- Config -----------------------------------------------------------------
|
// ---- Config -----------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub index: IndexConfig,
|
pub index: IndexConfig,
|
||||||
|
|
@ -157,16 +157,6 @@ impl Default for ModelConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
index: IndexConfig::default(),
|
|
||||||
search: SearchConfig::default(),
|
|
||||||
model: ModelConfig::default(),
|
|
||||||
power: PowerConfig::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct PowerConfig {
|
pub struct PowerConfig {
|
||||||
|
|
@ -255,8 +245,7 @@ pub struct StatusInfo {
|
||||||
pub fn send_request(req: &Request) -> std::io::Result<Response> {
|
pub fn send_request(req: &Request) -> std::io::Result<Response> {
|
||||||
let mut stream = UnixStream::connect(socket_path())?;
|
let mut stream = UnixStream::connect(socket_path())?;
|
||||||
|
|
||||||
let mut line = serde_json::to_string(req)
|
let mut line = serde_json::to_string(req).map_err(std::io::Error::other)?;
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
|
|
||||||
line.push('\n');
|
line.push('\n');
|
||||||
stream.write_all(line.as_bytes())?;
|
stream.write_all(line.as_bytes())?;
|
||||||
stream.flush()?;
|
stream.flush()?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue