Skip to content

Commit d87d87f

Browse files
committed
fix: do not set normalized name for existing chats and contacts in a migration
We got a report that application is not responding after update on Android and getting killed before it can start, suspected to be a slow SQL migration: <#7602> This change removes calculation of normalized names for existing chats and contacts added in <#7548> to exclude the possibility of this migration being slow. New chats and contacts will still get normalized names and all chats and contacts will get it when they are renamed.
1 parent bf72b3a commit d87d87f

File tree

1 file changed

+6
-44
lines changed

1 file changed

+6
-44
lines changed

src/sql/migrations.rs

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::log::warn;
1919
use crate::message::MsgId;
2020
use crate::provider::get_provider_info;
2121
use crate::sql::Sql;
22-
use crate::tools::{Time, inc_and_check, normalize_text, time_elapsed};
22+
use crate::tools::{Time, inc_and_check, time_elapsed};
2323
use crate::transport::ConfiguredLoginParam;
2424

2525
const DBVERSION: i32 = 68;
@@ -1456,52 +1456,14 @@ CREATE INDEX imap_sync_index ON imap_sync(transport_id, folder);
14561456

14571457
inc_and_check(&mut migration_version, 143)?;
14581458
if dbversion < migration_version {
1459-
let trans_fn = |t: &mut rusqlite::Transaction| {
1460-
t.execute_batch(
1461-
"
1459+
sql.execute_migration(
1460+
"
14621461
ALTER TABLE chats ADD COLUMN name_normalized TEXT;
14631462
ALTER TABLE contacts ADD COLUMN name_normalized TEXT;
14641463
",
1465-
)?;
1466-
1467-
let mut stmt = t.prepare("UPDATE chats SET name_normalized=? WHERE id=?")?;
1468-
for res in t
1469-
.prepare("SELECT id, name FROM chats LIMIT 10000")?
1470-
.query_map((), |row| {
1471-
let id: u32 = row.get(0)?;
1472-
let name: String = row.get(1)?;
1473-
Ok((id, name))
1474-
})?
1475-
{
1476-
let (id, name) = res?;
1477-
if let Some(name_normalized) = normalize_text(&name) {
1478-
stmt.execute((name_normalized, id))?;
1479-
}
1480-
}
1481-
1482-
let mut stmt = t.prepare("UPDATE contacts SET name_normalized=? WHERE id=?")?;
1483-
for res in t
1484-
.prepare(
1485-
"
1486-
SELECT id, IIF(name='', authname, name) FROM contacts
1487-
ORDER BY last_seen DESC LIMIT 10000
1488-
",
1489-
)?
1490-
.query_map((), |row| {
1491-
let id: u32 = row.get(0)?;
1492-
let name: String = row.get(1)?;
1493-
Ok((id, name))
1494-
})?
1495-
{
1496-
let (id, name) = res?;
1497-
if let Some(name_normalized) = normalize_text(&name) {
1498-
stmt.execute((name_normalized, id))?;
1499-
}
1500-
}
1501-
Ok(())
1502-
};
1503-
sql.execute_migration_transaction(trans_fn, migration_version)
1504-
.await?;
1464+
migration_version,
1465+
)
1466+
.await?;
15051467
}
15061468

15071469
let new_version = sql

0 commit comments

Comments
 (0)