server: instrument newsreader impl

This commit is contained in:
Bill Thiede 2024-12-16 08:56:05 -08:00
parent 94c03a9c7c
commit 0222985f4d

View File

@ -7,6 +7,7 @@ use scraper::Selector;
use shared::compute_color; use shared::compute_color;
use sqlx::postgres::PgPool; use sqlx::postgres::PgPool;
use tokio::sync::Mutex; use tokio::sync::Mutex;
use tracing::instrument;
use url::Url; use url::Url;
use crate::{ use crate::{
@ -52,6 +53,7 @@ fn site_from_tags(tags: &[String]) -> Option<String> {
None None
} }
#[instrument(name = "newsreader::count", skip_all, fields(query=%query))]
pub async fn count(pool: &PgPool, query: &Query) -> Result<usize, ServerError> { pub async fn count(pool: &PgPool, query: &Query) -> Result<usize, ServerError> {
if !is_newsreader_query(query) { if !is_newsreader_query(query) {
return Ok(0); return Ok(0);
@ -75,6 +77,7 @@ pub async fn count(pool: &PgPool, query: &Query) -> Result<usize, ServerError> {
Ok(row.count.unwrap_or(0).try_into().unwrap_or(0)) Ok(row.count.unwrap_or(0).try_into().unwrap_or(0))
} }
#[instrument(name = "newsreader::search", skip_all, fields(query=%query))]
pub async fn search( pub async fn search(
pool: &PgPool, pool: &PgPool,
after: Option<i32>, after: Option<i32>,
@ -141,6 +144,7 @@ pub async fn search(
} }
Ok(res) Ok(res)
} }
#[instrument(name = "newsreader::tags", skip_all, fields(needs_unread=%_needs_unread))]
pub async fn tags(pool: &PgPool, _needs_unread: bool) -> Result<Vec<Tag>, ServerError> { pub async fn tags(pool: &PgPool, _needs_unread: bool) -> Result<Vec<Tag>, ServerError> {
// TODO: optimize query by using needs_unread // TODO: optimize query by using needs_unread
let tags = sqlx::query_file!("sql/tags.sql").fetch_all(pool).await?; let tags = sqlx::query_file!("sql/tags.sql").fetch_all(pool).await?;
@ -164,6 +168,7 @@ pub async fn tags(pool: &PgPool, _needs_unread: bool) -> Result<Vec<Tag>, Server
Ok(tags) Ok(tags)
} }
#[instrument(name = "newsreader::thread", skip_all, fields(thread_id=%thread_id))]
pub async fn thread( pub async fn thread(
config: &Config, config: &Config,
pool: &PgPool, pool: &PgPool,
@ -280,6 +285,7 @@ pub async fn thread(
timestamp, timestamp,
})) }))
} }
#[instrument(name = "newsreader::set_read_status", skip_all, fields(query=%query,unread=%unread))]
pub async fn set_read_status<'ctx>( pub async fn set_read_status<'ctx>(
pool: &PgPool, pool: &PgPool,
query: &Query, query: &Query,