diff --git a/pgml-dashboard/src/lib.rs b/pgml-dashboard/src/lib.rs index f8e747d4e..0fa686a2f 100644 --- a/pgml-dashboard/src/lib.rs +++ b/pgml-dashboard/src/lib.rs @@ -19,6 +19,7 @@ pub mod guards; pub mod models; mod responses; mod templates; +mod utils; use guards::Cluster; use responses::{BadRequest, ResponseOk}; @@ -558,6 +559,7 @@ pub async fn uploaded_index(cluster: Cluster, table_name: &str) -> ResponseOk { let sql = templates::Sql::new( cluster.pool(), &format!("SELECT * FROM {} LIMIT 10", table_name), + true, ) .await .unwrap(); diff --git a/pgml-dashboard/src/models.rs b/pgml-dashboard/src/models.rs index 3fbcaaf79..13fb5fb63 100644 --- a/pgml-dashboard/src/models.rs +++ b/pgml-dashboard/src/models.rs @@ -296,18 +296,19 @@ impl Cell { pub async fn render(&mut self, pool: &PgPool) -> anyhow::Result<()> { let cell_type: CellType = self.cell_type.into(); - let rendering = match cell_type { + let (rendering, execution_time) = match cell_type { CellType::Sql => { - let queries = self.contents.split(";"); + let queries: Vec<&str> = self.contents.split(';').filter(|q| !q.trim().is_empty()).collect(); let mut rendering = String::new(); + let mut total_execution_duration = std::time::Duration::default(); + let render_individual_execution_duration = queries.len() > 1; for query in queries { - if query.trim().is_empty() { - continue; - } - - let result = match templates::Sql::new(pool, query).await { - Ok(sql) => sql.render_once()?, + let result = match templates::Sql::new(pool, query, render_individual_execution_duration).await { + Ok(sql) => { + total_execution_duration += sql.execution_duration; + sql.render_once()? + }, Err(err) => templates::SqlError { error: format!("{:?}", err), } @@ -317,7 +318,12 @@ impl Cell { rendering.push_str(&result); } - rendering + let execution_time = PgInterval{ + months: 0, + days: 0, + microseconds: total_execution_duration.as_micros().try_into().unwrap_or(0) + }; + (rendering, Some(execution_time)) } CellType::Markdown => { @@ -335,21 +341,23 @@ impl Cell { front_matter_delimiter: None, }; - format!( + (format!( "
TODO
+ Time: <%= crate::utils::format_microseconds(cell.execution_time.unwrap().microseconds as f64) %>
Time: <%= crate::utils::format_microseconds(execution_duration.as_micros() as f64) %>
+ <% } %>
<% } %>
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: