From c8b89029843d5d4f76455ab45cf7568bbca6d542 Mon Sep 17 00:00:00 2001 From: Nathaniel Cook Date: Fri, 19 Jan 2024 08:10:38 -0700 Subject: [PATCH] fix: use index for value_for_key query --- one/src/lib.rs | 1 - recon/src/recon/sqlitestore.rs | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/one/src/lib.rs b/one/src/lib.rs index 6666a7474..599e2cbbc 100644 --- a/one/src/lib.rs +++ b/one/src/lib.rs @@ -5,7 +5,6 @@ mod events; mod http; mod metrics; mod network; -mod sql; use std::{env, num::NonZeroUsize, path::PathBuf, time::Duration}; diff --git a/recon/src/recon/sqlitestore.rs b/recon/src/recon/sqlitestore.rs index 4a4c8575f..154771e70 100644 --- a/recon/src/recon/sqlitestore.rs +++ b/recon/src/recon/sqlitestore.rs @@ -366,7 +366,7 @@ where .bind(value) .bind(&self.sort_key) .bind(key.as_bytes()) - .fetch_all(&self.pool) + .fetch_all(self.pool.writer()) .await; match resp { Ok(_) => Ok(true), @@ -376,9 +376,13 @@ where #[instrument(skip(self))] async fn value_for_key(&mut self, key: &Self::Key) -> Result>> { - let query = sqlx::query("SELECT value FROM recon WHERE key=?;"); - let rows = query.bind(key.as_bytes()).fetch_all(&self.pool).await?; - if let Some(row) = rows.first() { + let query = sqlx::query("SELECT value FROM recon WHERE sort_key=? AND key=?;"); + let row = query + .bind(&self.sort_key) + .bind(key.as_bytes()) + .fetch_optional(self.pool.reader()) + .await?; + if let Some(row) = row { let value: Vec = row.get(0); Ok(Some(value)) } else {