Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ anyhow = "1"
base64 = "0.22"
bon = "3"
clap = { version = "4", features = ["derive"] }
debug_unsafe = "0.1"
hmac = "0.12"
reqwest-retry = "0.7"
serde = { version = "1", features = ["derive"] }
Expand Down
1 change: 0 additions & 1 deletion typesense/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ typesense_derive = { workspace = true, optional = true }
anyhow = { workspace = true }
base64 = { workspace = true }
bon = { workspace = true }
debug_unsafe = { workspace = true }
hmac = { workspace = true }
reqwest-retry = { workspace = true }
serde = { workspace = true }
Expand Down
13 changes: 7 additions & 6 deletions typesense/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@
use reqwest_retry::RetryTransientMiddleware;
pub use reqwest_retry::policies::ExponentialBackoff;

use debug_unsafe::{option::OptionUnwrapper, slice::SliceGetter};
use serde::{Serialize, de::DeserializeOwned};
use std::{
future::Future,
Expand Down Expand Up @@ -231,10 +230,10 @@
healthcheck_interval: Duration,
#[builder(default = ExponentialBackoff::builder().build_with_max_retries(3))]
/// The retry policy for transient network errors on a *single* node.
retry_policy: ExponentialBackoff,

Check warning on line 233 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `retry_policy`

Check warning on line 233 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `retry_policy`

Check warning on line 233 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `retry_policy`
#[builder(default = Duration::from_secs(5))]
/// The timeout for each individual network request.
connection_timeout: Duration,

Check warning on line 236 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `connection_timeout`

Check warning on line 236 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `connection_timeout`

Check warning on line 236 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `connection_timeout`
) -> Result<Self, &'static str> {
let is_nearest_node_set = nearest_node.is_some();

Expand All @@ -257,7 +256,7 @@
.with(RetryTransientMiddleware::new_with_policy(retry_policy))
.build();

if url.len() > 1 && url.chars().last().unwrap_safe_unchecked() == '/' {
if url.len() > 1 && matches!(url.chars().last(), Some('/')) {
url.pop();
}

Expand Down Expand Up @@ -294,8 +293,10 @@
/// Selects the next node to use for a request based on health and priority.
fn get_next_node(&self) -> &Node {
// if only one node (including nearest)
if self.nodes.len() == 1 {
return self.nodes.first().unwrap_safe_unchecked();
if self.nodes.len() == 1
&& let Some(first) = self.nodes.first()
{
return first;
}

let (nodes_len, mut index) = if self.is_nearest_node_set {
Expand All @@ -309,7 +310,7 @@
};

for _ in 0..self.nodes.len() {
let node = self.nodes.get_safe_unchecked(index);
let node = &self.nodes[index];

if node.is_healthy.load(Ordering::Relaxed)
|| node.last_accessed.read().unwrap().elapsed() >= self.healthcheck_interval
Expand All @@ -322,7 +323,7 @@
// If all nodes are unhealthy and not due for a check, just pick the next one in the round-robin.
// This gives it a chance to prove it has recovered.
index = self.current_node_index.load(Ordering::Relaxed) % self.nodes.len();
self.nodes.get_safe_unchecked(index)
&self.nodes[index]
}

/// For use in legacy APIs.
Expand Down
Loading