Remove slow is_project method
This commit is contained in:
parent
0c055e69b9
commit
018046ae66
|
@ -124,9 +124,6 @@ fn task_blocked(cache: &TaskCache, task: &Task) -> bool {
|
|||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn task_needs_sorting(cache: &TaskCache, uuid: &Uuid) -> Result<bool> {
|
||||
Ok(!cache.is_project(&uuid) && cache.get_parent(&uuid)? == None)
|
||||
}
|
||||
|
||||
fn task_inbox(cache: &TaskCache, task: &Task) -> bool {
|
||||
task.pending() && !task.tagged() && !task_blocked(cache, task)
|
||||
|
@ -170,6 +167,9 @@ fn enter_new_task<T: DialogProvider, S: Into<String>>(dialog: &mut T, msg: S) ->
|
|||
.build()?)
|
||||
}
|
||||
|
||||
fn needs_sorting(task: &Task) -> bool {
|
||||
!task.has_tag("project") && task.partof().map(|x| x.is_none()).unwrap_or(false)
|
||||
}
|
||||
|
||||
struct Kassandra {
|
||||
state: State,
|
||||
|
@ -194,6 +194,7 @@ impl Kassandra {
|
|||
self.cache.write()?;
|
||||
self.handle_active_tasks()?;
|
||||
self.clear_inbox()?;
|
||||
self.cache.refresh_tree();
|
||||
self.assure_all_sorted()?;
|
||||
|
||||
// check unread E-Mail + ak?
|
||||
|
@ -348,9 +349,8 @@ What's the progress?",
|
|||
.next()
|
||||
.is_some()
|
||||
{
|
||||
while let Some(uuid) = self.get_sorted_uuids(|t| {
|
||||
!t.obsolete() && task_needs_sorting(&self.cache, t.uuid()).unwrap_or(false)
|
||||
}).into_iter()
|
||||
while let Some(uuid) = self.get_sorted_uuids(|t| !t.obsolete() && needs_sorting(t))
|
||||
.into_iter()
|
||||
.next()
|
||||
{
|
||||
self.sort(&uuid)?;
|
||||
|
@ -406,7 +406,7 @@ What's the progress?",
|
|||
let mut options = self.cache
|
||||
.filter(|t| {
|
||||
t.pending() && t.partof().map(|partof| partof == parent).unwrap_or(false) &&
|
||||
(parent.is_some() || self.cache.is_project(t.uuid()))
|
||||
(parent.is_some() || t.has_tag("project"))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
options.sort_unstable_by_key(|t| t.entry().date());
|
||||
|
@ -688,7 +688,7 @@ What's the progress?",
|
|||
return Ok(());
|
||||
}
|
||||
}
|
||||
if task_needs_sorting(&self.cache, uuid)? {
|
||||
if needs_sorting(self.cache.get(uuid).chain_err(|| "unknown task")?) {
|
||||
self.sort(uuid)?;
|
||||
}
|
||||
if !self.make_project(uuid)? {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use task_hookrs::task::Task;
|
||||
|
@ -85,7 +87,6 @@ pub trait TreeCache {
|
|||
fn get_children(&self, uuid: &Uuid) -> Vec<&Task>;
|
||||
fn get_children_mut(&mut self, uuid: &Uuid) -> Vec<&mut Task>;
|
||||
fn get_project_path(&self, uuid: &Uuid) -> Result<String>;
|
||||
fn is_project(&self, uuid: &Uuid) -> bool;
|
||||
fn refresh_tree(&mut self);
|
||||
}
|
||||
fn get_project_name(cache: &TaskCache, task: &Task) -> Result<Option<String>> {
|
||||
|
@ -138,33 +139,48 @@ impl TreeCache for TaskCache {
|
|||
})
|
||||
}
|
||||
|
||||
fn is_project(&self, uuid: &Uuid) -> bool {
|
||||
self.get_children(uuid)
|
||||
.iter()
|
||||
.filter(|t| !t.obsolete())
|
||||
.count() > 0
|
||||
}
|
||||
|
||||
fn refresh_tree(&mut self) {
|
||||
let task_uuids = self.filter(|t| {
|
||||
!t.obsolete() &&
|
||||
(get_project_name(self, t)
|
||||
.map(|path| path.as_ref() != t.project())
|
||||
.unwrap_or(false) ||
|
||||
(self.is_project(t.uuid()) != t.has_tag("project")))
|
||||
}).map(|t| t.uuid().clone())
|
||||
.collect::<Vec<_>>();
|
||||
for task_uuid in task_uuids {
|
||||
let new_project_name = get_project_name(self, self.get(&task_uuid).expect("Bug"))
|
||||
.expect("Bug");
|
||||
let is_project = self.is_project(&task_uuid);
|
||||
let task = self.get_mut(&task_uuid).expect("Bug");
|
||||
task.set_project(new_project_name);
|
||||
if is_project {
|
||||
task.add_tag("project");
|
||||
let parents = self.filter(|t| !t.obsolete())
|
||||
.filter_map(|t| t.partof().unwrap_or(None))
|
||||
.collect::<HashSet<_>>();
|
||||
let mut add = vec![];
|
||||
let mut remove = vec![];
|
||||
let mut set = vec![];
|
||||
|
||||
for (project_name, project, tagged, uuid) in
|
||||
self.filter(|t| !t.obsolete()).map(|t| {
|
||||
(
|
||||
get_project_name(self, t),
|
||||
t.project(),
|
||||
t.has_tag("project"),
|
||||
t.uuid().clone(),
|
||||
)
|
||||
})
|
||||
{
|
||||
if parents.contains(&uuid) {
|
||||
if !tagged {
|
||||
add.push(uuid);
|
||||
}
|
||||
} else {
|
||||
task.remove_tag("project");
|
||||
if tagged {
|
||||
remove.push(uuid);
|
||||
}
|
||||
}
|
||||
if let Ok(project_name) = project_name {
|
||||
if project != project_name.as_ref() {
|
||||
set.push((uuid, project_name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for uuid in add {
|
||||
self.get_mut(&uuid).expect("Bug").add_tag("project");
|
||||
}
|
||||
for uuid in remove {
|
||||
self.get_mut(&uuid).expect("Bug").remove_tag("project");
|
||||
}
|
||||
for (uuid, name) in set {
|
||||
self.get_mut(&uuid).expect("Bug").set_project(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue