@@ -6,7 +6,7 @@ use crate::{
66 flamegraph,
77 } ,
88 pastila,
9- utils:: { highlight_sql, open_graph_in_browser } ,
9+ utils:: { highlight_sql, share_graph } ,
1010 view:: { self , Navigation } ,
1111} ;
1212use anyhow:: { Result , anyhow} ;
@@ -31,7 +31,7 @@ pub enum Event {
3131 LastQueryLog ( String , RelativeDateTime , RelativeDateTime , u64 ) ,
3232 // (view_name, args)
3333 TextLog ( & ' static str , TextLogArguments ) ,
34- // [bool (true - show in TUI, false - open in browser ), type, start, end]
34+ // [bool (true - show in TUI, false - share via pastila ), type, start, end]
3535 ServerFlameGraph ( bool , TraceType , DateTime < Local > , DateTime < Local > ) ,
3636 // (type, bool (true - show in TUI, false - open in browser), start time, end time, [query_ids])
3737 QueryFlameGraph (
@@ -55,7 +55,7 @@ pub enum Event {
5555 // (database, query)
5656 ExplainPipeline ( String , String ) ,
5757 // (database, query)
58- ExplainPipelineOpenGraphInBrowser ( String , String ) ,
58+ ExplainPipelineShareGraph ( String , String ) ,
5959 // (database, query)
6060 ExplainPlanIndexes ( String , String ) ,
6161 // (database, table)
@@ -74,7 +74,7 @@ pub enum Event {
7474 TableParts ( String , String ) ,
7575 // (database, table)
7676 AsynchronousInserts ( String , String ) ,
77- // (content to share)
77+ // (content to share via pastila )
7878 ShareLogs ( String ) ,
7979}
8080
@@ -94,9 +94,7 @@ impl Event {
9494 Event :: ExplainSyntax ( ..) => "ExplainSyntax" . to_string ( ) ,
9595 Event :: ExplainPlan ( ..) => "ExplainPlan" . to_string ( ) ,
9696 Event :: ExplainPipeline ( ..) => "ExplainPipeline" . to_string ( ) ,
97- Event :: ExplainPipelineOpenGraphInBrowser ( ..) => {
98- "ExplainPipelineOpenGraphInBrowser" . to_string ( )
99- }
97+ Event :: ExplainPipelineShareGraph ( ..) => "ExplainPipelineShareGraph" . to_string ( ) ,
10098 Event :: ExplainPlanIndexes ( ..) => "ExplainPlanIndexes" . to_string ( ) ,
10199 Event :: ShowCreateTable ( ..) => "ShowCreateTable" . to_string ( ) ,
102100 Event :: SQLQuery ( view_name, _query) => format ! ( "SQLQuery({})" , view_name) ,
@@ -541,21 +539,24 @@ async fn process_event(context: ContextArc, event: Event, need_clear: &mut bool)
541539 } ) )
542540 . map_err ( |_| anyhow ! ( "Cannot send message to UI" ) ) ?;
543541 }
544- Event :: ExplainPipelineOpenGraphInBrowser ( database, query) => {
542+ Event :: ExplainPipelineShareGraph ( database, query) => {
545543 let pipeline = clickhouse
546544 . explain_pipeline_graph ( database. as_str ( ) , query. as_str ( ) )
547545 . await ?
548546 . join ( "\n " ) ;
549- cb_sink
550- . send ( Box :: new ( move |siv : & mut cursive:: Cursive | {
551- open_graph_in_browser ( pipeline)
552- . or_else ( |err| {
553- siv. add_layer ( views:: Dialog :: info ( err. to_string ( ) ) ) ;
554- return anyhow:: Ok ( ( ) ) ;
555- } )
556- . unwrap ( ) ;
557- } ) )
558- . map_err ( |_| anyhow ! ( "Cannot send message to UI" ) ) ?;
547+
548+ // Upload graph to pastila and open in browser
549+ match share_graph ( pipeline, & pastila_clickhouse_host, & pastila_url) . await {
550+ Ok ( _) => { }
551+ Err ( err) => {
552+ let error_msg = err. to_string ( ) ;
553+ cb_sink
554+ . send ( Box :: new ( move |siv : & mut cursive:: Cursive | {
555+ siv. add_layer ( views:: Dialog :: info ( error_msg) ) ;
556+ } ) )
557+ . map_err ( |_| anyhow ! ( "Cannot send message to UI" ) ) ?;
558+ }
559+ }
559560 }
560561 Event :: ShowCreateTable ( database, table) => {
561562 let create_statement = clickhouse
@@ -718,8 +719,7 @@ async fn process_event(context: ContextArc, event: Event, need_clear: &mut bool)
718719 }
719720 Event :: ShareLogs ( content) => {
720721 let url =
721- pastila:: upload_logs_encrypted ( & content, & pastila_clickhouse_host, & pastila_url)
722- . await ?;
722+ pastila:: upload_encrypted ( & content, & pastila_clickhouse_host, & pastila_url) . await ?;
723723
724724 let url_clone = url. clone ( ) ;
725725 cb_sink
0 commit comments