mirror of
https://github.com/astro/buzzrelay.git
synced 2024-11-21 19:51:00 +00:00
db: sprinkle with metrics::histogram!
This commit is contained in:
parent
a3c87c9311
commit
6aeab7f7aa
1 changed files with 11 additions and 2 deletions
13
src/db.rs
13
src/db.rs
|
@ -1,8 +1,8 @@
|
|||
use std::sync::Arc;
|
||||
use std::{sync::Arc, time::Instant};
|
||||
use metrics::histogram;
|
||||
use tokio_postgres::{Client, Error, NoTls, Statement};
|
||||
|
||||
|
||||
|
||||
const CREATE_SCHEMA_COMMANDS: &[&str] = &[
|
||||
"CREATE TABLE IF NOT EXISTS follows (id TEXT, inbox TEXT, actor TEXT, UNIQUE (inbox, actor))",
|
||||
"CREATE INDEX IF NOT EXISTS follows_actor ON follows (actor) INCLUDE (inbox)",
|
||||
|
@ -58,20 +58,29 @@ impl Database {
|
|||
}
|
||||
|
||||
pub async fn add_follow(&self, id: &str, inbox: &str, actor: &str) -> Result<(), Error> {
|
||||
let t1 = Instant::now();
|
||||
self.inner.client.execute(&self.inner.add_follow, &[&id, &inbox, &actor])
|
||||
.await?;
|
||||
let t2 = Instant::now();
|
||||
histogram!("sql", t2 - t1, "query" => "add_follow");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn del_follow(&self, id: &str, actor: &str) -> Result<(), Error> {
|
||||
let t1 = Instant::now();
|
||||
self.inner.client.execute(&self.inner.del_follow, &[&id, &actor])
|
||||
.await?;
|
||||
let t2 = Instant::now();
|
||||
histogram!("sql", t2 - t1, "query" => "del_follow");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_following_inboxes(&self, actor: &str) -> Result<impl Iterator<Item = String>, Error> {
|
||||
let t1 = Instant::now();
|
||||
let rows = self.inner.client.query(&self.inner.get_following_inboxes, &[&actor])
|
||||
.await?;
|
||||
let t2 = Instant::now();
|
||||
histogram!("sql", t2 - t1, "query" => "get_following_inboxes");
|
||||
Ok(rows.into_iter()
|
||||
.map(|row| row.get(0))
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue