refactor: address feedback
parent
9283432a0f
commit
cdb4f43d62
|
@ -242,7 +242,7 @@ impl QueryDatabase for QueryCatalogAccess {
|
||||||
// When the query token is dropped the query entry's completion time
|
// When the query token is dropped the query entry's completion time
|
||||||
// will be set.
|
// will be set.
|
||||||
let entry = self.query_log.push(query_type, query_text);
|
let entry = self.query_log.push(query_type, query_text);
|
||||||
QueryCompletedToken::new(move || self.query_log.set_completed(Arc::clone(&entry)))
|
QueryCompletedToken::new(move || self.query_log.set_completed(entry))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,9 @@ use std::{
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use time::{Time, TimeProvider};
|
use time::{Time, TimeProvider};
|
||||||
|
|
||||||
|
// The query duration used for queries still running.
|
||||||
|
const UNCOMPLETED_DURATION: i64 = -1;
|
||||||
|
|
||||||
/// Information about a single query that was executed
|
/// Information about a single query that was executed
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct QueryLogEntry {
|
pub struct QueryLogEntry {
|
||||||
|
@ -33,7 +36,7 @@ impl QueryLogEntry {
|
||||||
query_type,
|
query_type,
|
||||||
query_text,
|
query_text,
|
||||||
issue_time,
|
issue_time,
|
||||||
query_completed_duration: (-1_i64).into(),
|
query_completed_duration: UNCOMPLETED_DURATION.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +45,7 @@ impl QueryLogEntry {
|
||||||
.query_completed_duration
|
.query_completed_duration
|
||||||
.load(atomic::Ordering::Relaxed)
|
.load(atomic::Ordering::Relaxed)
|
||||||
{
|
{
|
||||||
-1 => None,
|
UNCOMPLETED_DURATION => None,
|
||||||
d => Some(Duration::from_nanos(d as u64)),
|
d => Some(Duration::from_nanos(d as u64)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +57,7 @@ impl QueryLogEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores a fixed number `QueryExcutions` -- handles locking
|
/// Stores a fixed number `QueryExecutions` -- handles locking
|
||||||
/// internally so can be shared across multiple
|
/// internally so can be shared across multiple
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct QueryLog {
|
pub struct QueryLog {
|
||||||
|
|
|
@ -81,7 +81,7 @@ pub trait QueryChunkMeta: Sized {
|
||||||
/// a `QueryDatabase`. It is used to trigger side-effects (such as query timing)
|
/// a `QueryDatabase`. It is used to trigger side-effects (such as query timing)
|
||||||
/// on query completion.
|
/// on query completion.
|
||||||
pub struct QueryCompletedToken<'a> {
|
pub struct QueryCompletedToken<'a> {
|
||||||
f: Box<dyn Fn() + Send + 'a>,
|
f: Option<Box<dyn FnOnce() + Send + 'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Debug for QueryCompletedToken<'a> {
|
impl<'a> Debug for QueryCompletedToken<'a> {
|
||||||
|
@ -91,14 +91,18 @@ impl<'a> Debug for QueryCompletedToken<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> QueryCompletedToken<'a> {
|
impl<'a> QueryCompletedToken<'a> {
|
||||||
pub fn new(f: impl Fn() + Send + 'a) -> Self {
|
pub fn new(f: impl FnOnce() + Send + 'a) -> Self {
|
||||||
Self { f: Box::new(f) }
|
Self {
|
||||||
|
f: Some(Box::new(f)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for QueryCompletedToken<'a> {
|
impl<'a> Drop for QueryCompletedToken<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
(self.f)()
|
if let Some(f) = self.f.take() {
|
||||||
|
(f)()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue