mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
avoid clone
This commit is contained in:
@@ -524,8 +524,13 @@ pub async fn save(
|
|||||||
let mut newest_location_id = 0;
|
let mut newest_location_id = 0;
|
||||||
|
|
||||||
for location in locations {
|
for location in locations {
|
||||||
// TODO: can this clone be avoided?
|
let &Location {
|
||||||
let location = location.clone();
|
timestamp,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
accuracy,
|
||||||
|
..
|
||||||
|
} = location;
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.with_conn(move |mut conn| {
|
.with_conn(move |mut conn| {
|
||||||
@@ -537,29 +542,29 @@ pub async fn save(
|
|||||||
VALUES (?,?,?,?,?,?,?);",
|
VALUES (?,?,?,?,?,?,?);",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let exists = stmt_test.exists(paramsv![location.timestamp, contact_id as i32])?;
|
let exists = stmt_test.exists(paramsv![timestamp, contact_id as i32])?;
|
||||||
|
|
||||||
if independent || !exists {
|
if independent || !exists {
|
||||||
stmt_insert.execute(paramsv![
|
stmt_insert.execute(paramsv![
|
||||||
location.timestamp,
|
timestamp,
|
||||||
contact_id as i32,
|
contact_id as i32,
|
||||||
chat_id,
|
chat_id,
|
||||||
location.latitude,
|
latitude,
|
||||||
location.longitude,
|
longitude,
|
||||||
location.accuracy,
|
accuracy,
|
||||||
independent,
|
independent,
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
if location.timestamp > newest_timestamp {
|
if timestamp > newest_timestamp {
|
||||||
// okay to drop, as we use cached prepared statements
|
// okay to drop, as we use cached prepared statements
|
||||||
drop(stmt_test);
|
drop(stmt_test);
|
||||||
drop(stmt_insert);
|
drop(stmt_insert);
|
||||||
newest_timestamp = location.timestamp;
|
newest_timestamp = timestamp;
|
||||||
newest_location_id = crate::sql::get_rowid2(
|
newest_location_id = crate::sql::get_rowid2(
|
||||||
&mut conn,
|
&mut conn,
|
||||||
"locations",
|
"locations",
|
||||||
"timestamp",
|
"timestamp",
|
||||||
location.timestamp,
|
timestamp,
|
||||||
"from_id",
|
"from_id",
|
||||||
contact_id as i32,
|
contact_id as i32,
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user