Skip to content

Commit 6a3f215

Browse files
committed
avoid cloning variables when not needed in run_sql
1 parent 12a75c9 commit 6a3f215

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/webserver/database/sqlpage_functions/functions.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,14 @@ async fn run_sql<'a>(
368368
)
369369
.await
370370
.with_context(|| format!("run_sql: invalid path {sql_file_path:?}"))?;
371-
let mut tmp_req = request.clone();
372-
if let Some(variables) = variables {
371+
let mut tmp_req = if let Some(variables) = variables {
372+
let mut tmp_req = request.clone_without_variables();
373373
let variables: ParamMap = serde_json::from_str(&variables)?;
374374
tmp_req.get_variables = variables;
375-
tmp_req.post_variables = Default::default();
376-
}
375+
tmp_req
376+
} else {
377+
request.clone()
378+
};
377379
if tmp_req.clone_depth > 8 {
378380
anyhow::bail!("Too many nested inclusions. run_sql can include a file that includes another file, but the depth is limited to 8 levels. \n\
379381
Executing sqlpage.run_sql('{sql_file_path}') would exceed this limit. \n\

src/webserver/http_request_info.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ pub struct RequestInfo {
4040
pub clone_depth: u8,
4141
}
4242

43-
impl Clone for RequestInfo {
44-
fn clone(&self) -> Self {
43+
impl RequestInfo {
44+
pub fn clone_without_variables(&self) -> Self {
4545
Self {
4646
method: self.method.clone(),
4747
path: self.path.clone(),
4848
protocol: self.protocol.clone(),
49-
get_variables: self.get_variables.clone(),
50-
post_variables: self.post_variables.clone(),
49+
get_variables: ParamMap::new(),
50+
post_variables: ParamMap::new(),
5151
uploaded_files: self.uploaded_files.clone(),
5252
headers: self.headers.clone(),
5353
client_ip: self.client_ip,
@@ -59,6 +59,15 @@ impl Clone for RequestInfo {
5959
}
6060
}
6161

62+
impl Clone for RequestInfo {
63+
fn clone(&self) -> Self {
64+
let mut clone = self.clone_without_variables();
65+
clone.get_variables = self.get_variables.clone();
66+
clone.post_variables = self.post_variables.clone();
67+
clone
68+
}
69+
}
70+
6271
pub(crate) async fn extract_request_info(
6372
req: &mut ServiceRequest,
6473
app_state: Arc<AppState>,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set html = 'It ';
2+
select 'dynamic' as component, sqlpage.run_sql('tests/display_text.sql') as properties;
3+
set html = 'works !';
4+
select 'dynamic' as component, sqlpage.run_sql('tests/display_text.sql') as properties;

0 commit comments

Comments
 (0)