Skip to content

Commit 1a2e355

Browse files
committed
feat: migrations: Use tools::Time to measure time for logging
There's a comment in `tools` that tells to use `tools::Time` instead of `Instant` because on Android the latter doesn't advance in the deep sleep mode. The only place except `migrations` where `Instant` is used is tests, but we don't run CI on Android. It's unlikely that Delta Chat goes to the deep sleep while executing migrations, but still possible, so let's use `tools::Time` as everywhere else.
1 parent 192a6a2 commit 1a2e355

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/sql/migrations.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::collections::BTreeMap;
44
use std::collections::BTreeSet;
5-
use std::time::{Duration, Instant};
5+
use std::time::Duration;
66

77
use anyhow::{Context as _, Result, ensure};
88
use deltachat_contact_tools::EmailAddress;
@@ -1237,13 +1237,13 @@ CREATE INDEX gossip_timestamp_index ON gossip_timestamp (chat_id, fingerprint);
12371237

12381238
inc_and_check(&mut migration_version, 132)?;
12391239
if dbversion < migration_version {
1240-
let start = Instant::now();
1240+
let start = Time::now();
12411241
sql.execute_migration_transaction(|t| migrate_key_contacts(context, t), migration_version)
12421242
.await?;
12431243
info!(
12441244
context,
12451245
"key-contacts migration took {:?} in total.",
1246-
start.elapsed()
1246+
time_elapsed(&start),
12471247
);
12481248
// Schedule `msgs_to_key_contacts()`.
12491249
context

src/tools.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use std::str::from_utf8;
1414
// `Instant` may use `libc::clock_gettime(CLOCK_MONOTONIC)`, e.g. on Android, and does not advance
1515
// while being in deep sleep mode, we use `SystemTime` instead, but add an alias for it to document
1616
// why `Instant` isn't used in those places. Also this can help to switch to another clock impl if
17-
// we find any.
17+
// we find any. Another reason is that `Instant` may reintroduce panics in the future versions:
18+
// https://doc.rust-lang.org/1.87.0/std/time/struct.Instant.html#method.elapsed.
1819
use std::time::Duration;
1920
pub use std::time::SystemTime as Time;
2021
#[cfg(not(test))]

0 commit comments

Comments
 (0)