From 930305edcdca690c4dda938ef41eda2f502274b2 Mon Sep 17 00:00:00 2001 From: rUv Date: Fri, 26 Dec 2025 17:49:54 +0000 Subject: [PATCH] fix(postgres): Fix additional clippy warnings in workers module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove unnecessary cast in types/vector.rs:549 - Use div_ceil() instead of manual computation in workers/ipc.rs - Replace redundant closure with function reference in workers/ipc.rs - Derive Default for MaintenanceStats in workers/maintenance.rs - Derive Default for TaskPriority enum in workers/queue.rs - Use or_default() instead of or_insert_with(Vec::new) in workers/mod.rs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- crates/ruvector-postgres/src/types/vector.rs | 2 +- crates/ruvector-postgres/src/workers/ipc.rs | 6 +++--- .../src/workers/maintenance.rs | 20 +------------------ crates/ruvector-postgres/src/workers/mod.rs | 5 +---- crates/ruvector-postgres/src/workers/queue.rs | 11 ++++------ 5 files changed, 10 insertions(+), 34 deletions(-) diff --git a/crates/ruvector-postgres/src/types/vector.rs b/crates/ruvector-postgres/src/types/vector.rs index 430c8980..e18c24b2 100644 --- a/crates/ruvector-postgres/src/types/vector.rs +++ b/crates/ruvector-postgres/src/types/vector.rs @@ -546,7 +546,7 @@ pub extern "C" fn ruvector_send(fcinfo: pg_sys::FunctionCallInfo) -> pg_sys::Dat let bytea_ptr = pg_sys::palloc(bytea_size) as *mut pg_sys::bytea; // Set size - pgrx::varlena::set_varsize_4b(bytea_ptr as *mut pg_sys::varlena, bytea_size as i32); + pgrx::varlena::set_varsize_4b(bytea_ptr, bytea_size as i32); // Copy data let bytea_data = pgrx::varlena::vardata_any(bytea_ptr as *const pg_sys::varlena) as *mut u8; diff --git a/crates/ruvector-postgres/src/workers/ipc.rs b/crates/ruvector-postgres/src/workers/ipc.rs index 78c830ec..ae9c08f0 100644 --- a/crates/ruvector-postgres/src/workers/ipc.rs +++ b/crates/ruvector-postgres/src/workers/ipc.rs @@ -406,7 +406,7 @@ impl LargePayloadSegment { return None; } - let slots_needed = (size + SLOT_SIZE - 1) / SLOT_SIZE; + let slots_needed = size.div_ceil(SLOT_SIZE); // Find contiguous free slots for start_slot in 0..=(NUM_SLOTS - slots_needed) { @@ -471,7 +471,7 @@ impl LargePayloadSegment { /// Free a previously allocated payload pub fn free(&self, payload_ref: &PayloadRef) { let start_slot = payload_ref.offset as usize / SLOT_SIZE; - let slots = (payload_ref.length as usize + SLOT_SIZE - 1) / SLOT_SIZE; + let slots = (payload_ref.length as usize).div_ceil(SLOT_SIZE); for slot in start_slot..(start_slot + slots) { let word = slot / 64; @@ -896,7 +896,7 @@ fn prepare_operation( shmem .large_payload_segment .write(payload_ref.offset as usize, &serialized) - .map_err(|e| IpcError::SharedMemoryError(e))?; + .map_err(IpcError::SharedMemoryError)?; Ok((Operation::LargePayloadRef(payload_ref), Some(payload_ref))) } diff --git a/crates/ruvector-postgres/src/workers/maintenance.rs b/crates/ruvector-postgres/src/workers/maintenance.rs index c512e5df..f03d85c9 100644 --- a/crates/ruvector-postgres/src/workers/maintenance.rs +++ b/crates/ruvector-postgres/src/workers/maintenance.rs @@ -177,7 +177,7 @@ pub struct TierCandidate { // ============================================================================ /// Maintenance operation statistics -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct MaintenanceStats { /// Total cycles completed pub cycles_completed: u64, @@ -203,24 +203,6 @@ pub struct MaintenanceStats { pub last_cycle_at: u64, } -impl Default for MaintenanceStats { - fn default() -> Self { - Self { - cycles_completed: 0, - indexes_maintained: 0, - compactions_performed: 0, - bytes_reclaimed: 0, - tier_promotions: 0, - tier_demotions: 0, - stats_collections: 0, - cleanup_operations: 0, - total_time_us: 0, - last_cycle_duration_us: 0, - last_cycle_at: 0, - } - } -} - /// Atomic maintenance statistics pub struct MaintenanceStatsAtomic { cycles_completed: AtomicU64, diff --git a/crates/ruvector-postgres/src/workers/mod.rs b/crates/ruvector-postgres/src/workers/mod.rs index f954d142..19c75f37 100644 --- a/crates/ruvector-postgres/src/workers/mod.rs +++ b/crates/ruvector-postgres/src/workers/mod.rs @@ -131,10 +131,7 @@ impl WorkerRegistry { /// Register a new worker pub fn register(&self, worker_type: WorkerType, handle: WorkerHandle) { let mut workers = self.workers.write(); - workers - .entry(worker_type) - .or_insert_with(Vec::new) - .push(handle); + workers.entry(worker_type).or_default().push(handle); self.total_spawned.fetch_add(1, Ordering::SeqCst); } diff --git a/crates/ruvector-postgres/src/workers/queue.rs b/crates/ruvector-postgres/src/workers/queue.rs index 0a1bf3ab..2c2c3dfd 100644 --- a/crates/ruvector-postgres/src/workers/queue.rs +++ b/crates/ruvector-postgres/src/workers/queue.rs @@ -74,24 +74,21 @@ impl std::fmt::Display for TaskType { } /// Task priority levels -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +#[derive( + Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, +)] pub enum TaskPriority { /// Critical priority - processed immediately Critical = 0, /// High priority High = 1, /// Medium priority (default) + #[default] Medium = 2, /// Low priority - background tasks Low = 3, } -impl Default for TaskPriority { - fn default() -> Self { - TaskPriority::Medium - } -} - impl std::fmt::Display for TaskPriority { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self {