add TimelineCache helper methods

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-07-15 16:04:50 -04:00
parent 4db6f37017
commit 95e9e4326a

View File

@@ -38,6 +38,15 @@ impl<'a, M> Vitality<'a, M> {
}
}
impl<'a> IntoIterator for &'a mut TimelineCache {
type Item = (&'a TimelineKind, &'a mut Timeline);
type IntoIter = std::collections::hash_map::IterMut<'a, TimelineKind, Timeline>;
fn into_iter(self) -> Self::IntoIter {
self.timelines.iter_mut()
}
}
impl TimelineCache {
/// Pop a timeline from the timeline cache. This only removes the timeline
/// if it has reached 0 subscribers, meaning it was the last one to be
@@ -95,6 +104,14 @@ impl TimelineCache {
self.timelines.insert(id, timeline);
}
pub fn insert(&mut self, id: TimelineKind, timeline: Timeline) {
if let Some(_cur_timeline) = self.timelines.get_mut(&id) {
return;
};
self.timelines.insert(id, timeline);
}
/// Get and/or update the notes associated with this timeline
pub fn notes<'a>(
&'a mut self,
@@ -190,6 +207,18 @@ impl TimelineCache {
open_result
}
pub fn get(&self, id: &TimelineKind) -> Option<&Timeline> {
self.timelines.get(id)
}
pub fn get_mut(&mut self, id: &TimelineKind) -> Option<&mut Timeline> {
self.timelines.get_mut(id)
}
pub fn num_timelines(&self) -> usize {
self.timelines.len()
}
}
/// Look for new thread notes since our last fetch