mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 14:08:23 +00:00
calendar store: Add method for bulk insert
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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(
|
||||||
&mut tx,
|
Self::log_object_operation(
|
||||||
&principal,
|
&mut tx,
|
||||||
&cal_id,
|
&principal,
|
||||||
&object_id,
|
&cal_id,
|
||||||
ChangeOperation::Add,
|
object.get_id(),
|
||||||
)
|
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)?;
|
||||||
|
|
||||||
self.send_push_notification(
|
if let Some(sync_token) = sync_token {
|
||||||
CollectionOperationInfo::Content { sync_token },
|
self.send_push_notification(
|
||||||
self.get_calendar(&principal, &cal_id, true)
|
CollectionOperationInfo::Content { sync_token },
|
||||||
.await?
|
self.get_calendar(&principal, &cal_id, true)
|
||||||
.push_topic,
|
.await?
|
||||||
);
|
.push_topic,
|
||||||
|
);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user