calendar store: Add method for bulk insert

This commit is contained in:
Lennart K
2025-12-20 11:48:05 +01:00
parent b50ea478db
commit 28c925301e
4 changed files with 40 additions and 26 deletions

View File

@@ -77,13 +77,23 @@ pub trait CalendarStore: Send + Sync + 'static {
object_id: &str, object_id: &str,
show_deleted: bool, show_deleted: bool,
) -> Result<CalendarObject, Error>; ) -> Result<CalendarObject, Error>;
async fn put_objects(
&self,
principal: String,
cal_id: String,
objects: Vec<CalendarObject>,
overwrite: bool,
) -> Result<(), Error>;
async fn put_object( async fn put_object(
&self, &self,
principal: String, principal: String,
cal_id: String, cal_id: String,
object: CalendarObject, object: CalendarObject,
overwrite: bool, overwrite: bool,
) -> Result<(), Error>; ) -> Result<(), Error> {
self.put_objects(principal, cal_id, vec![object], overwrite)
.await
}
async fn delete_object( async fn delete_object(
&self, &self,
principal: &str, principal: &str,

View File

@@ -147,15 +147,15 @@ impl CalendarStore for CombinedCalendarStore {
.await .await
} }
async fn put_object( async fn put_objects(
&self, &self,
principal: String, principal: String,
cal_id: String, cal_id: String,
object: rustical_ical::CalendarObject, objects: Vec<rustical_ical::CalendarObject>,
overwrite: bool, overwrite: bool,
) -> Result<(), crate::Error> { ) -> Result<(), crate::Error> {
self.store_for_id(&cal_id) self.store_for_id(&cal_id)
.put_object(principal, cal_id, object, overwrite) .put_objects(principal, cal_id, objects, overwrite)
.await .await
} }

View File

@@ -394,11 +394,11 @@ impl CalendarStore for SqliteAddressbookStore {
} }
#[instrument] #[instrument]
async fn put_object( async fn put_objects(
&self, &self,
_principal: String, _principal: String,
_cal_id: String, _cal_id: String,
_object: CalendarObject, _objects: Vec<CalendarObject>,
_overwrite: bool, _overwrite: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
Err(Error::ReadOnly) Err(Error::ReadOnly)

View File

@@ -776,11 +776,11 @@ impl CalendarStore for SqliteCalendarStore {
} }
#[instrument] #[instrument]
async fn put_object( async fn put_objects(
&self, &self,
principal: String, principal: String,
cal_id: String, cal_id: String,
object: CalendarObject, objects: Vec<CalendarObject>,
overwrite: bool, overwrite: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
let mut tx = self let mut tx = self
@@ -789,33 +789,37 @@ impl CalendarStore for SqliteCalendarStore {
.await .await
.map_err(crate::Error::from)?; .map_err(crate::Error::from)?;
let object_id = object.get_id().to_owned();
let calendar = Self::_get_calendar(&mut *tx, &principal, &cal_id, true).await?; let calendar = Self::_get_calendar(&mut *tx, &principal, &cal_id, true).await?;
if calendar.subscription_url.is_some() { if calendar.subscription_url.is_some() {
// We cannot commit an object to a subscription calendar // We cannot commit an object to a subscription calendar
return Err(Error::ReadOnly); return Err(Error::ReadOnly);
} }
Self::_put_object(&mut *tx, &principal, &cal_id, &object, overwrite).await?; let mut sync_token = None;
for object in objects {
let sync_token = Self::log_object_operation( sync_token = Some(
Self::log_object_operation(
&mut tx, &mut tx,
&principal, &principal,
&cal_id, &cal_id,
&object_id, object.get_id(),
ChangeOperation::Add, ChangeOperation::Add,
) )
.await?; .await?,
);
Self::_put_object(&mut *tx, &principal, &cal_id, &object, overwrite).await?;
}
tx.commit().await.map_err(crate::Error::from)?; tx.commit().await.map_err(crate::Error::from)?;
if let Some(sync_token) = sync_token {
self.send_push_notification( self.send_push_notification(
CollectionOperationInfo::Content { sync_token }, CollectionOperationInfo::Content { sync_token },
self.get_calendar(&principal, &cal_id, true) self.get_calendar(&principal, &cal_id, true)
.await? .await?
.push_topic, .push_topic,
); );
}
Ok(()) Ok(())
} }