mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 01:12:24 +00:00
frontend: Add basic information about collections
This commit is contained in:
@@ -3,8 +3,8 @@ use async_trait::async_trait;
|
||||
use derive_more::derive::Constructor;
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_store::{
|
||||
Addressbook, AddressbookStore, CollectionOperation, CollectionOperationInfo, Error,
|
||||
synctoken::format_synctoken,
|
||||
Addressbook, AddressbookStore, CollectionMetadata, CollectionOperation,
|
||||
CollectionOperationInfo, Error, synctoken::format_synctoken,
|
||||
};
|
||||
use sqlx::{Acquire, Executor, Sqlite, SqlitePool, Transaction};
|
||||
use tokio::sync::mpsc::Sender;
|
||||
@@ -223,6 +223,28 @@ impl SqliteAddressbookStore {
|
||||
Ok((objects, deleted_objects, new_synctoken))
|
||||
}
|
||||
|
||||
async fn _list_objects<'e, E: Executor<'e, Database = Sqlite>>(
|
||||
executor: E,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
) -> Result<Vec<(u64, bool)>, rustical_store::Error> {
|
||||
struct ObjectEntry {
|
||||
length: u64,
|
||||
deleted: bool,
|
||||
}
|
||||
Ok(sqlx::query_as!(
|
||||
ObjectEntry,
|
||||
"SELECT length(vcf) AS 'length!: u64', deleted_at AS 'deleted!: bool' FROM addressobjects WHERE principal = ? AND addressbook_id = ?",
|
||||
principal,
|
||||
addressbook_id
|
||||
)
|
||||
.fetch_all(executor)
|
||||
.await.map_err(crate::Error::from)?
|
||||
.into_iter()
|
||||
.map(|row| (row.length, row.deleted))
|
||||
.collect())
|
||||
}
|
||||
|
||||
async fn _get_objects<'e, E: Executor<'e, Database = Sqlite>>(
|
||||
executor: E,
|
||||
principal: &str,
|
||||
@@ -442,6 +464,29 @@ impl AddressbookStore for SqliteAddressbookStore {
|
||||
Self::_sync_changes(&self.db, principal, addressbook_id, synctoken).await
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
async fn addressbook_metadata(
|
||||
&self,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
) -> Result<CollectionMetadata, rustical_store::Error> {
|
||||
let mut sizes = vec![];
|
||||
let mut deleted_sizes = vec![];
|
||||
for (size, deleted) in Self::_list_objects(&self.db, principal, addressbook_id).await? {
|
||||
if deleted {
|
||||
deleted_sizes.push(size)
|
||||
} else {
|
||||
sizes.push(size)
|
||||
}
|
||||
}
|
||||
Ok(CollectionMetadata {
|
||||
len: sizes.len(),
|
||||
deleted_len: deleted_sizes.len(),
|
||||
size: sizes.iter().sum(),
|
||||
deleted_size: deleted_sizes.iter().sum(),
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
async fn get_objects(
|
||||
&self,
|
||||
|
||||
@@ -5,7 +5,7 @@ use derive_more::derive::Constructor;
|
||||
use rustical_ical::{CalDateTime, CalendarObject, CalendarObjectType};
|
||||
use rustical_store::calendar_store::CalendarQuery;
|
||||
use rustical_store::synctoken::format_synctoken;
|
||||
use rustical_store::{Calendar, CalendarStore, Error};
|
||||
use rustical_store::{Calendar, CalendarStore, CollectionMetadata, Error};
|
||||
use rustical_store::{CollectionOperation, CollectionOperationInfo};
|
||||
use sqlx::types::chrono::NaiveDateTime;
|
||||
use sqlx::{Acquire, Executor, Sqlite, SqlitePool, Transaction};
|
||||
@@ -242,6 +242,28 @@ impl SqliteCalendarStore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn _list_objects<'e, E: Executor<'e, Database = Sqlite>>(
|
||||
executor: E,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
) -> Result<Vec<(u64, bool)>, rustical_store::Error> {
|
||||
struct ObjectEntry {
|
||||
length: u64,
|
||||
deleted: bool,
|
||||
}
|
||||
Ok(sqlx::query_as!(
|
||||
ObjectEntry,
|
||||
"SELECT length(ics) AS 'length!: u64', deleted_at AS 'deleted!: bool' FROM calendarobjects WHERE principal = ? AND cal_id = ?",
|
||||
principal,
|
||||
cal_id
|
||||
)
|
||||
.fetch_all(executor)
|
||||
.await.map_err(crate::Error::from)?
|
||||
.into_iter()
|
||||
.map(|row| (row.length, row.deleted))
|
||||
.collect())
|
||||
}
|
||||
|
||||
async fn _get_objects<'e, E: Executor<'e, Database = Sqlite>>(
|
||||
executor: E,
|
||||
principal: &str,
|
||||
@@ -552,6 +574,28 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
Self::_calendar_query(&self.db, principal, cal_id, query).await
|
||||
}
|
||||
|
||||
async fn calendar_metadata(
|
||||
&self,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
) -> Result<CollectionMetadata, Error> {
|
||||
let mut sizes = vec![];
|
||||
let mut deleted_sizes = vec![];
|
||||
for (size, deleted) in Self::_list_objects(&self.db, principal, cal_id).await? {
|
||||
if deleted {
|
||||
deleted_sizes.push(size)
|
||||
} else {
|
||||
sizes.push(size)
|
||||
}
|
||||
}
|
||||
Ok(CollectionMetadata {
|
||||
len: sizes.len(),
|
||||
deleted_len: deleted_sizes.len(),
|
||||
size: sizes.iter().sum(),
|
||||
deleted_size: deleted_sizes.iter().sum(),
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
async fn get_objects(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user