Skip to content

Commit 36ee62c

Browse files
dlachaumesfauvel
authored andcommitted
Update expand implementation that improves the insert performances
1 parent 82aec88 commit 36ee62c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

internal/mithril-persistence/src/sqlite/condition.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,21 @@ impl WhereCondition {
7070

7171
/// Turn the condition into a SQL string representation.
7272
pub fn expand(self) -> (String, Vec<Value>) {
73-
let mut expression = self.condition.expand();
73+
let expression = self.condition.expand();
7474
let parameters = self.parameters;
75-
let mut param_index = 1;
7675
//
7776
// Replace parameters placeholders by numerated parameters.
78-
loop {
79-
if !expression.contains("?*") {
80-
break;
81-
}
82-
expression = expression.replacen("?*", &format!("?{param_index}"), 1);
77+
let mut final_expression = "".to_string();
78+
let mut value = "".to_string();
79+
let mut param_index = 0;
80+
for sql_part in expression.split("?*") {
81+
final_expression.push_str(&value);
82+
final_expression.push_str(sql_part);
8383
param_index += 1;
84+
value = format!("?{}", param_index);
8485
}
8586

86-
(expression, parameters)
87+
(final_expression.to_string(), parameters)
8788
}
8889

8990
/// Instanciate a condition with a `IN` statement.

0 commit comments

Comments
 (0)