Skip to content

Commit

Permalink
fix: use index for value_for_key query
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Jan 19, 2024
1 parent 212504f commit c8b8902
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 0 additions & 1 deletion one/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod events;
mod http;
mod metrics;
mod network;
mod sql;

use std::{env, num::NonZeroUsize, path::PathBuf, time::Duration};

Expand Down
12 changes: 8 additions & 4 deletions recon/src/recon/sqlitestore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -376,9 +376,13 @@ where

#[instrument(skip(self))]
async fn value_for_key(&mut self, key: &Self::Key) -> Result<Option<Vec<u8>>> {
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<u8> = row.get(0);
Ok(Some(value))
} else {
Expand Down

0 comments on commit c8b8902

Please sign in to comment.