mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-09 21:29:06 -05:00
feat: cache prepared statements and trace expanded SQL queries
This commit is contained in:
parent
c6a8807485
commit
3e4ae4aeec
|
@ -28,7 +28,7 @@ secp256k1 = {version = "0.21", features = ["rand", "rand-std", "serde", "bitcoin
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = {version = "1.0", features = ["preserve_order"]}
|
serde_json = {version = "1.0", features = ["preserve_order"]}
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
rusqlite = { version = "0.26", features = ["limits","bundled"]}
|
rusqlite = { version = "0.26", features = ["limits","bundled","modern_sqlite", "trace"]}
|
||||||
r2d2 = "0.8"
|
r2d2 = "0.8"
|
||||||
r2d2_sqlite = "0.19"
|
r2d2_sqlite = "0.19"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
|
|
|
@ -753,10 +753,13 @@ pub async fn db_query(
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut slow_first_event;
|
let mut slow_first_event;
|
||||||
let mut last_successful_send = Instant::now();
|
let mut last_successful_send = Instant::now();
|
||||||
if let Ok(conn) = pool.get() {
|
if let Ok(mut conn) = pool.get() {
|
||||||
// execute the query. Don't cache, since queries vary so much.
|
// execute the query.
|
||||||
let mut stmt = conn.prepare(&q)?;
|
// make the actual SQL query (with parameters inserted) available
|
||||||
|
conn.trace(Some(|x| {trace!("SQL trace: {:?}", x)}));
|
||||||
|
let mut stmt = conn.prepare_cached(&q)?;
|
||||||
let mut event_rows = stmt.query(rusqlite::params_from_iter(p))?;
|
let mut event_rows = stmt.query(rusqlite::params_from_iter(p))?;
|
||||||
|
|
||||||
let mut first_result = true;
|
let mut first_result = true;
|
||||||
while let Some(row) = event_rows.next()? {
|
while let Some(row) = event_rows.next()? {
|
||||||
let first_event_elapsed = start.elapsed();
|
let first_event_elapsed = start.elapsed();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user