@@ -296,18 +296,19 @@ impl Cell {
296296pub async fn render ( & mut self , pool : & PgPool ) -> anyhow:: Result < ( ) > {
297297let cell_type: CellType =self . cell_type . into ( ) ;
298298
299- let rendering =match cell_type{
299+ let ( rendering, execution_time ) =match cell_type{
300300CellType :: Sql =>{
301- let queries =self . contents . split ( ";" ) ;
301+ let queries: Vec < & str > =self . contents . split ( ';' ) . filter ( |q| !q . trim ( ) . is_empty ( ) ) . collect ( ) ;
302302let mut rendering =String :: new ( ) ;
303+ let mut total_execution_duration = std:: time:: Duration :: default ( ) ;
304+ let render_individual_execution_duration = queries. len ( ) >1 ;
303305
304306for queryin queries{
305- if query. trim ( ) . is_empty ( ) {
306- continue ;
307- }
308-
309- let result =match templates:: Sql :: new ( pool, query) . await {
310- Ok ( sql) => sql. render_once ( ) ?,
307+ let result =match templates:: Sql :: new ( pool, query, render_individual_execution_duration) . await {
308+ Ok ( sql) =>{
309+ total_execution_duration += sql. execution_duration ;
310+ sql. render_once ( ) ?
311+ } ,
311312Err ( err) => templates:: SqlError {
312313error : format ! ( "{:?}" , err) ,
313314}
@@ -317,7 +318,12 @@ impl Cell {
317318 rendering. push_str ( & result) ;
318319}
319320
320- rendering
321+ let execution_time =PgInterval {
322+ months : 0 ,
323+ days : 0 ,
324+ microseconds : total_execution_duration. as_micros ( ) . try_into ( ) . unwrap_or ( 0 )
325+ } ;
326+ ( rendering, Some ( execution_time) )
321327}
322328
323329CellType :: Markdown =>{
@@ -335,21 +341,23 @@ impl Cell {
335341front_matter_delimiter : None ,
336342} ;
337343
338- format ! (
344+ ( format ! (
339345"<div class=\" markdown-body\" >{}</div>" ,
340346 markdown_to_html( & self . contents, & options)
341- )
347+ ) , None )
342348}
343349} ;
344350
345351 sqlx:: query!(
346- "UPDATE pgml.notebook_cells SET rendering = $1 WHERE id = $2 " ,
352+ "UPDATE pgml.notebook_cells SET rendering = $1, execution_time = $2 WHERE id = $3 " ,
347353 rendering,
354+ execution_time,
348355self . id
349356)
350357. execute ( pool)
351358. await ?;
352359
360+ self . execution_time = execution_time;
353361self . rendering =Some ( rendering) ;
354362
355363Ok ( ( ) )