From cbb4378581105716154de5226b8945ecb826f9e7 Mon Sep 17 00:00:00 2001 From: daladim Date: Tue, 23 Mar 2021 00:13:03 +0100 Subject: [PATCH] last_modified is no longer required --- src/calendar/cached_calendar.rs | 49 +++------------------------------ src/event.rs | 6 ---- src/item.rs | 8 ------ src/task.rs | 10 +------ src/traits.rs | 10 ------- tests/sync.rs | 35 ++++++++++------------- 6 files changed, 20 insertions(+), 98 deletions(-) diff --git a/src/calendar/cached_calendar.rs b/src/calendar/cached_calendar.rs index 8bbc433..bd54c0e 100644 --- a/src/calendar/cached_calendar.rs +++ b/src/calendar/cached_calendar.rs @@ -33,15 +33,6 @@ impl CachedCalendar { deleted_items: BTreeMap::new(), } } - - /// Returns the list of tasks that this calendar contains - pub async fn get_tasks(&self) -> Result, Box> { - self.get_tasks_modified_since(None).await - } - /// Returns the tasks that have been last-modified after `since` - pub async fn get_tasks_modified_since(&self, since: Option>) -> Result, Box> { - self.get_items_modified_since(since, Some(SearchFilter::Tasks)).await - } } #[async_trait] @@ -106,43 +97,11 @@ impl PartialCalendar for CachedCalendar { #[async_trait] impl CompleteCalendar for CachedCalendar { - /// Returns the items that have been deleted after `since` - async fn get_items_deleted_since(&self, since: DateTime) -> Result, Box> { - Ok(self.deleted_items.range(since..) - .map(|(_key, id)| id.clone()) - .collect()) - } - /// Returns the list of items that this calendar contains async fn get_items(&self) -> Result, Box> { - self.get_items_modified_since(None, None).await - } - - async fn get_items_modified_since(&self, since: Option>, filter: Option) -> Result, Box> { - let filter = filter.unwrap_or_default(); - - let mut map = HashMap::new(); - - for (_id, item) in &self.items { - match since { - None => (), - Some(since) => if item.last_modified() < since { - continue; - }, - } - - match filter { - SearchFilter::Tasks => { - if item.is_task() == false { - continue; - } - }, - _ => (), - } - - map.insert(item.id().clone(), item); - } - - Ok(map) + Ok(self.items.iter() + .map(|(id, item)| (id.clone(), item)) + .collect() + ) } } diff --git a/src/event.rs b/src/event.rs index c60e2b8..7f8cbf1 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,7 +1,6 @@ //! Calendar events use serde::{Deserialize, Serialize}; -use chrono::{Utc, DateTime}; use crate::item::ItemId; use crate::item::SyncStatus; @@ -12,7 +11,6 @@ use crate::item::SyncStatus; pub struct Event { id: ItemId, name: String, - last_modified: DateTime, sync_status: SyncStatus, } @@ -25,10 +23,6 @@ impl Event { &self.name } - pub fn last_modified(&self) -> DateTime { - self.last_modified - } - pub fn sync_status(&self) -> &SyncStatus { &self.sync_status } diff --git a/src/item.rs b/src/item.rs index a9b2ca6..9ab7a85 100644 --- a/src/item.rs +++ b/src/item.rs @@ -2,7 +2,6 @@ use std::fmt::{Display, Formatter}; use std::str::FromStr; use serde::{Deserialize, Serialize}; -use chrono::{Utc, DateTime}; use url::Url; use crate::resource::Resource; @@ -30,13 +29,6 @@ impl Item { } } - pub fn last_modified(&self) -> DateTime { - match self { - Item::Event(e) => e.last_modified(), - Item::Task(t) => t.last_modified(), - } - } - pub fn sync_status(&self) -> &SyncStatus { match self { Item::Event(e) => e.sync_status(), diff --git a/src/task.rs b/src/task.rs index 137c6ae..3569c6e 100644 --- a/src/task.rs +++ b/src/task.rs @@ -1,4 +1,3 @@ -use chrono::{Utc, DateTime}; use serde::{Deserialize, Serialize}; use crate::item::ItemId; @@ -10,8 +9,6 @@ pub struct Task { /// The task unique ID, that will never change id: ItemId, - /// The last modification date of this task - last_modified: DateTime, /// The sync status of this item sync_status: SyncStatus, @@ -23,11 +20,10 @@ pub struct Task { impl Task { /// Create a new Task - pub fn new(name: String, id: ItemId, last_modified: DateTime, sync_status: SyncStatus) -> Self { + pub fn new(name: String, id: ItemId, sync_status: SyncStatus) -> Self { Self { id, name, - last_modified, sync_status, completed: false, } @@ -36,27 +32,23 @@ impl Task { pub fn id(&self) -> &ItemId { &self.id } pub fn name(&self) -> &str { &self.name } pub fn completed(&self) -> bool { self.completed } - pub fn last_modified(&self) -> DateTime { self.last_modified } pub fn sync_status(&self) -> &SyncStatus { &self.sync_status } pub fn set_sync_status(&mut self, new_status: SyncStatus) { self.sync_status = new_status; } fn update_last_modified(&mut self) { - self.last_modified = Utc::now(); } /// Rename a task. /// This updates its "last modified" field pub fn set_name(&mut self, new_name: String) { - self.update_last_modified(); self.name = new_name; } pub fn set_completed(&mut self, new_value: bool) { // TODO: either require a reference to the DataSource, so that it is aware // or change a flag here, and the DataSource will be able to check the flags of all its content (but then the Calendar should only give a reference/Arc, not a clone) - self.update_last_modified(); self.completed = new_value; } } diff --git a/src/traits.rs b/src/traits.rs index dbff2da..e3135b7 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -3,7 +3,6 @@ use std::collections::{HashMap, HashSet}; use std::sync::{Arc, Mutex}; use async_trait::async_trait; -use chrono::{DateTime, Utc}; use crate::item::Item; use crate::item::ItemId; @@ -79,15 +78,6 @@ pub trait PartialCalendar { /// Usually, this is a calendar fully stored on a local disk #[async_trait] pub trait CompleteCalendar : PartialCalendar { - /// Returns the items that have been deleted after `since` - /// - /// See also [`PartialCalendar::get_items_deleted_since`] - async fn get_items_deleted_since(&self, since: DateTime) -> Result, Box>; - - /// Returns the items that have been last-modified after `since` - async fn get_items_modified_since(&self, since: Option>, filter: Option) - -> Result, Box>; - /// Returns the list of items that this calendar contains async fn get_items(&self) -> Result, Box>; } diff --git a/tests/sync.rs b/tests/sync.rs index 1ac53f3..ca7e89a 100644 --- a/tests/sync.rs +++ b/tests/sync.rs @@ -3,7 +3,6 @@ use std::path::PathBuf; use std::sync::{Arc, Mutex}; -use chrono::{Utc, TimeZone}; use url::Url; use my_tasks::traits::CalDavSource; @@ -56,23 +55,19 @@ async fn populate_test_provider() -> Provider Provider Provider