@@ -288,18 +288,19 @@ impl Cell {
288288pub async fn render ( & mut self , pool : & PgPool ) -> anyhow:: Result < ( ) > {
289289let cell_type: CellType =self . cell_type . into ( ) ;
290290
291- let rendering =match cell_type{
291+ let ( rendering, execution_time ) =match cell_type{
292292CellType :: Sql =>{
293- let queries =self . contents . split ( ";" ) ;
293+ let queries: Vec < & str > =self . contents . split ( ';' ) . filter ( |q| !q . trim ( ) . is_empty ( ) ) . collect ( ) ;
294294let mut rendering =String :: new ( ) ;
295+ let mut total_execution_duration = std:: time:: Duration :: default ( ) ;
296+ let render_individual_execution_duration = queries. len ( ) >1 ;
295297
296298for queryin queries{
297- if query. trim ( ) . is_empty ( ) {
298- continue ;
299- }
300-
301- let result =match templates:: Sql :: new ( pool, query) . await {
302- Ok ( sql) => sql. render_once ( ) ?,
299+ let result =match templates:: Sql :: new ( pool, query, render_individual_execution_duration) . await {
300+ Ok ( sql) =>{
301+ total_execution_duration += sql. execution_duration ;
302+ sql. render_once ( ) ?
303+ } ,
303304Err ( err) => templates:: SqlError {
304305error : format ! ( "{:?}" , err) ,
305306}
@@ -309,7 +310,12 @@ impl Cell {
309310 rendering. push_str ( & result) ;
310311}
311312
312- rendering
313+ let execution_time =PgInterval {
314+ months : 0 ,
315+ days : 0 ,
316+ microseconds : total_execution_duration. as_micros ( ) . try_into ( ) . unwrap_or ( 0 )
317+ } ;
318+ ( rendering, Some ( execution_time) )
313319}
314320
315321CellType :: Markdown =>{
@@ -327,21 +333,23 @@ impl Cell {
327333front_matter_delimiter : None ,
328334} ;
329335
330- format ! (
336+ ( format ! (
331337"<div class=\" markdown-body\" >{}</div>" ,
332338 markdown_to_html( & self . contents, & options)
333- )
339+ ) , None )
334340}
335341} ;
336342
337343 sqlx:: query!(
338- "UPDATE pgml.notebook_cells SET rendering = $1 WHERE id = $2 " ,
344+ "UPDATE pgml.notebook_cells SET rendering = $1, execution_time = $2 WHERE id = $3 " ,
339345 rendering,
346+ execution_time,
340347self . id
341348)
342349. execute ( pool)
343350. await ?;
344351
352+ self . execution_time = execution_time;
345353self . rendering =Some ( rendering) ;
346354
347355Ok ( ( ) )