server: add tracing for graphql handling

This commit is contained in:
2024-12-14 10:09:33 -08:00
parent 416d82042f
commit 872771b02a
6 changed files with 565 additions and 225 deletions

View File

@@ -9,6 +9,7 @@ use tantivy::{
schema::{Facet, IndexRecordOption, Value},
DocAddress, Index, Searcher, TantivyDocument, TantivyError, Term,
};
use tracing::instrument;
use crate::{
compute_offset_limit,
@@ -42,6 +43,7 @@ impl TantivyConnection {
db_path: tantivy_db_path.to_string(),
})
}
#[instrument(name = "tantivy::refresh", skip_all)]
pub async fn refresh(&self, pool: &PgPool) -> Result<(), ServerError> {
let start_time = std::time::Instant::now();
let p_uids: Vec<_> = sqlx::query_file!("sql/all-uids.sql")
@@ -167,6 +169,7 @@ impl TantivyConnection {
index_writer.commit()?;
Ok(())
}
#[instrument(name = "tantivy::reindex_thread", skip_all, fields(query=?query))]
pub async fn reindex_thread(&self, pool: &PgPool, query: &Query) -> Result<(), ServerError> {
let uids: Vec<_> = query
.uids
@@ -176,6 +179,7 @@ impl TantivyConnection {
.collect();
Ok(self.reindex_uids(pool, &uids).await?)
}
#[instrument(name = "tantivy::reindex_all", skip_all)]
pub async fn reindex_all(&self, pool: &PgPool) -> Result<(), ServerError> {
let rows = sqlx::query_file!("sql/all-posts.sql")
.fetch_all(pool)
@@ -224,6 +228,7 @@ impl TantivyConnection {
Ok((searcher, Box::new(search_query)))
}
#[instrument(name="tantivy::count", skip_all, fields(query=?query))]
pub async fn count(&self, query: &Query) -> Result<usize, ServerError> {
if !is_tantivy_query(query) {
return Ok(0);
@@ -233,6 +238,7 @@ impl TantivyConnection {
let (searcher, query) = self.searcher_and_query(&query)?;
Ok(searcher.search(&query, &Count)?)
}
#[instrument(name="tantivy::search", skip_all, fields(query=?query))]
pub async fn search(
&self,
pool: &PgPool,