mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
breaking(sqlite): Add metadata into calendar store for more efficient queries in the future
This commit is contained in:
@@ -21,11 +21,23 @@ CREATE TABLE calendarobjects (
|
||||
ics TEXT NOT NULL,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at DATETIME,
|
||||
|
||||
-- For more efficient calendar-queries
|
||||
first_occurence DATE,
|
||||
last_occurence DATE,
|
||||
etag TEXT,
|
||||
object_type INTEGER NOT NULL, -- VEVENT(0)/VTODO(1)/VJOURNAL(2)
|
||||
|
||||
PRIMARY KEY (principal, cal_id, id),
|
||||
FOREIGN KEY (principal, cal_id)
|
||||
REFERENCES calendars (principal, id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX idx_calobjs_first_occurence ON calendarobjects (first_occurence);
|
||||
CREATE INDEX idx_calobjs_last_occurence ON calendarobjects (last_occurence);
|
||||
CREATE INDEX idx_calobjs_etag ON calendarobjects (etag);
|
||||
CREATE INDEX idx_calobjs_obj_type ON calendarobjects (object_type);
|
||||
|
||||
CREATE TABLE calendarobjectchangelog (
|
||||
principal TEXT NOT NULL,
|
||||
cal_id TEXT NOT NULL,
|
||||
@@ -37,3 +49,5 @@ CREATE TABLE calendarobjectchangelog (
|
||||
FOREIGN KEY (principal, cal_id)
|
||||
REFERENCES calendars (principal, id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX idx_calobj_log_cal ON calendarobjectchangelog (cal_id);
|
||||
|
||||
@@ -32,3 +32,5 @@ CREATE TABLE addressobjectchangelog (
|
||||
FOREIGN KEY (principal, addressbook_id)
|
||||
REFERENCES addressbooks (principal, id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX idx_addrobj_log_cal ON addressobjectchangelog (addressbook_id);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::ChangeOperation;
|
||||
use async_trait::async_trait;
|
||||
use derive_more::derive::Constructor;
|
||||
use rustical_store::calendar::CalDateTime;
|
||||
use rustical_store::synctoken::format_synctoken;
|
||||
use rustical_store::{Calendar, CalendarObject, CalendarStore, Error};
|
||||
use rustical_store::{CollectionOperation, CollectionOperationType};
|
||||
@@ -277,22 +278,45 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
|
||||
let (object_id, ics) = (object.get_id(), object.get_ics());
|
||||
|
||||
let first_occurence = object
|
||||
.get_first_occurence()
|
||||
.ok()
|
||||
.flatten()
|
||||
.as_ref()
|
||||
.map(CalDateTime::date);
|
||||
let last_occurence = object
|
||||
.get_last_occurence()
|
||||
.ok()
|
||||
.flatten()
|
||||
.as_ref()
|
||||
.map(CalDateTime::date);
|
||||
let etag = object.get_etag();
|
||||
let object_type = object.get_object_type() as u8;
|
||||
|
||||
(if overwrite {
|
||||
sqlx::query!(
|
||||
"REPLACE INTO calendarobjects (principal, cal_id, id, ics) VALUES (?, ?, ?, ?)",
|
||||
principal,
|
||||
cal_id,
|
||||
object_id,
|
||||
ics
|
||||
)
|
||||
} else {
|
||||
// If the object already exists a database error is thrown and handled in error.rs
|
||||
sqlx::query!(
|
||||
"INSERT INTO calendarobjects (principal, cal_id, id, ics) VALUES (?, ?, ?, ?)",
|
||||
"REPLACE INTO calendarobjects (principal, cal_id, id, ics, first_occurence, last_occurence, etag, object_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
principal,
|
||||
cal_id,
|
||||
object_id,
|
||||
ics,
|
||||
first_occurence,
|
||||
last_occurence,
|
||||
etag,
|
||||
object_type,
|
||||
)
|
||||
} else {
|
||||
// If the object already exists a database error is thrown and handled in error.rs
|
||||
sqlx::query!(
|
||||
"INSERT INTO calendarobjects (principal, cal_id, id, ics, first_occurence, last_occurence, etag, object_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
principal,
|
||||
cal_id,
|
||||
object_id,
|
||||
ics,
|
||||
first_occurence,
|
||||
last_occurence,
|
||||
etag,
|
||||
object_type,
|
||||
)
|
||||
})
|
||||
.execute(&mut *tx)
|
||||
|
||||
Reference in New Issue
Block a user