@@ -406,12 +406,7 @@ impl Database for AllDbs {
406406mod sqlite {
407407 use async_trait:: async_trait;
408408 use color_eyre:: eyre:: OptionExt ;
409- use std:: {
410- collections:: HashMap ,
411- path:: Path ,
412- sync:: Arc ,
413- time:: { Duration , SystemTime } ,
414- } ;
409+ use std:: { collections:: HashMap , path:: Path , sync:: Arc , time:: Duration } ;
415410 use tokio_rusqlite:: { Connection , OpenFlags } ;
416411
417412 use crate :: { helpers, responses, Database , ROWS_PER_PAGE , SAMPLE_DB } ;
@@ -787,41 +782,31 @@ mod sqlite {
787782 }
788783
789784 async fn query ( & self , query : String ) -> color_eyre:: Result < responses:: Query > {
790- let start = SystemTime :: now ( ) ;
791- let timeout = self . query_timeout ;
792-
793- let res = self
794- . conn
795- . call ( move |conn| {
796- let mut stmt = conn. prepare ( & query) ?;
797- let columns = stmt
798- . column_names ( )
799- . into_iter ( )
800- . map ( ToOwned :: to_owned)
801- . collect :: < Vec < _ > > ( ) ;
785+ let res = self . conn . call ( move |conn| {
786+ let mut stmt = conn. prepare ( & query) ?;
787+ let columns = stmt
788+ . column_names ( )
789+ . into_iter ( )
790+ . map ( ToOwned :: to_owned)
791+ . collect :: < Vec < _ > > ( ) ;
802792
803- let columns_len = columns. len ( ) ;
804- let rows: Result < Vec < _ > , _ > = stmt
805- . query_map ( ( ) , |r| {
806- let now = SystemTime :: now ( ) ;
807- if now - timeout >= start {
808- // just used a random error, we just want to bail out
809- return Err ( rusqlite:: Error :: InvalidQuery ) ;
810- }
793+ let columns_len = columns. len ( ) ;
794+ let rows: Result < Vec < _ > , _ > = stmt
795+ . query_map ( ( ) , |r| {
796+ let mut rows = Vec :: with_capacity ( columns_len) ;
797+ for i in 0 ..columns_len {
798+ let val = helpers:: rusqlite_value_to_json ( r. get_ref ( i) ?) ;
799+ rows. push ( val) ;
800+ }
801+ Ok ( rows)
802+ } ) ?
803+ . collect ( ) ;
804+ let rows = rows?;
811805
812- let mut rows = Vec :: with_capacity ( columns_len) ;
813- for i in 0 ..columns_len {
814- let val = helpers:: rusqlite_value_to_json ( r. get_ref ( i) ?) ;
815- rows. push ( val) ;
816- }
817- Ok ( rows)
818- } ) ?
819- . collect ( ) ;
820- let rows = rows?;
806+ Ok ( responses:: Query { columns, rows } )
807+ } ) ;
821808
822- Ok ( responses:: Query { columns, rows } )
823- } )
824- . await ?;
809+ let res = tokio:: time:: timeout ( self . query_timeout , res) . await ??;
825810
826811 Ok ( res)
827812 }
0 commit comments