Improve cache cleaning when contacts table doesn't exist
This commit is contained in:
parent
541fe10f1a
commit
10e496e36f
@ -184,11 +184,21 @@ impl Identity {
|
||||
None
|
||||
}
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
pub fn clear_cache() -> Result<(), rusqlite::Error> {
|
||||
let db = Connection::open(get_database_path())?;
|
||||
let mut stmt = db.prepare(&format!("SELECT name FROM sqlite_master WHERE type='table' AND name='{}'", CONTACTS_TABLE))?;
|
||||
let mut rows = stmt.query([])?;
|
||||
let contact_table_exists = rows.next()?.is_some();
|
||||
if contact_table_exists {
|
||||
#[allow(unused_must_use)]
|
||||
{
|
||||
db.execute(&format!("DELETE FROM {} WHERE contact_uuid IS NULL", FILES_TABLE), []);
|
||||
db.execute(&format!("DELETE FROM {} WHERE uuid NOT IN (SELECT avatar FROM {})", AVATARS_TABLE, CONTACTS_TABLE), []);
|
||||
}
|
||||
} else {
|
||||
db.execute(&format!("DROP TABLE IF EXISTS {}", FILES_TABLE), [])?;
|
||||
db.execute(&format!("DROP TABLE IF EXISTS {}", AVATARS_TABLE), [])?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user