birthday_calendar: Refactor insert_birthday_calendar

This commit is contained in:
Lennart
2025-11-22 18:32:53 +01:00
parent ba3b64a9c4
commit 96f221f721
3 changed files with 5 additions and 3 deletions

1
Cargo.lock generated
View File

@@ -3230,6 +3230,7 @@ dependencies = [
"rustical_store_sqlite", "rustical_store_sqlite",
"rustical_xml", "rustical_xml",
"serde", "serde",
"sha2",
"thiserror 2.0.17", "thiserror 2.0.17",
"tokio", "tokio",
"tower", "tower",

View File

@@ -118,15 +118,16 @@ impl SqliteAddressbookStore {
#[instrument] #[instrument]
pub async fn _insert_birthday_calendar<'e, E: Executor<'e, Database = Sqlite>>( pub async fn _insert_birthday_calendar<'e, E: Executor<'e, Database = Sqlite>>(
executor: E, executor: E,
addressbook: Addressbook, addressbook: &Addressbook,
) -> Result<(), rustical_store::Error> { ) -> Result<(), rustical_store::Error> {
let birthday_name = addressbook let birthday_name = addressbook
.displayname .displayname
.as_ref()
.map(|name| format!("{name} birthdays")); .map(|name| format!("{name} birthdays"));
let birthday_push_topic = { let birthday_push_topic = {
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
hasher.update("birthdays"); hasher.update("birthdays");
hasher.update(addressbook.push_topic); hasher.update(&addressbook.push_topic);
format!("{:x}", hasher.finalize()) format!("{:x}", hasher.finalize())
}; };

View File

@@ -467,7 +467,7 @@ impl AddressbookStore for SqliteAddressbookStore {
.await .await
.map_err(crate::Error::from)?; .map_err(crate::Error::from)?;
Self::_insert_addressbook(&mut *tx, &addressbook).await?; Self::_insert_addressbook(&mut *tx, &addressbook).await?;
Self::_insert_birthday_calendar(&mut *tx, addressbook).await?; Self::_insert_birthday_calendar(&mut *tx, &addressbook).await?;
tx.commit().await.map_err(crate::Error::from)?; tx.commit().await.map_err(crate::Error::from)?;
Ok(()) Ok(())
} }