mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Fix bug with new events not affecting the UI until you click around
This commit is contained in:
parent
f780fe2498
commit
38f41de240
40
src/feed.rs
40
src/feed.rs
@ -95,36 +95,17 @@ impl Feed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_general(&self) -> Vec<Id> {
|
pub fn get_general(&self) -> Vec<Id> {
|
||||||
let now = Instant::now();
|
self.maybe_recompute();
|
||||||
if *self.last_computed.read() + Duration::from_millis(*self.interval_ms.read() as u64) < now
|
|
||||||
{
|
|
||||||
let now = now;
|
|
||||||
task::spawn(async move {
|
|
||||||
if let Err(e) = GLOBALS.feed.recompute().await {
|
|
||||||
tracing::error!("{}", e);
|
|
||||||
}
|
|
||||||
*GLOBALS.feed.last_computed.write() = now;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
self.general_feed.read().clone()
|
self.general_feed.read().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_replies(&self) -> Vec<Id> {
|
pub fn get_replies(&self) -> Vec<Id> {
|
||||||
let now = Instant::now();
|
self.maybe_recompute();
|
||||||
if *self.last_computed.read() + Duration::from_millis(*self.interval_ms.read() as u64) < now
|
|
||||||
{
|
|
||||||
let now = now;
|
|
||||||
task::spawn(async move {
|
|
||||||
if let Err(e) = GLOBALS.feed.recompute().await {
|
|
||||||
tracing::error!("{}", e);
|
|
||||||
}
|
|
||||||
*GLOBALS.feed.last_computed.write() = now;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
self.replies_feed.read().clone()
|
self.replies_feed.read().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_person_feed(&self, person: PublicKeyHex) -> Vec<Id> {
|
pub fn get_person_feed(&self, person: PublicKeyHex) -> Vec<Id> {
|
||||||
|
self.maybe_recompute();
|
||||||
let mut events: Vec<Event> = GLOBALS
|
let mut events: Vec<Event> = GLOBALS
|
||||||
.events
|
.events
|
||||||
.iter()
|
.iter()
|
||||||
@ -152,6 +133,7 @@ impl Feed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_thread_parent(&self) -> Option<Id> {
|
pub fn get_thread_parent(&self) -> Option<Id> {
|
||||||
|
self.maybe_recompute();
|
||||||
*self.thread_parent.read()
|
*self.thread_parent.read()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,6 +142,20 @@ impl Feed {
|
|||||||
*self.thread_parent.write() = Some(id);
|
*self.thread_parent.write() = Some(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn maybe_recompute(&self) {
|
||||||
|
let now = Instant::now();
|
||||||
|
if *self.last_computed.read() + Duration::from_millis(*self.interval_ms.read() as u64) < now
|
||||||
|
{
|
||||||
|
let now = now;
|
||||||
|
task::spawn(async move {
|
||||||
|
if let Err(e) = GLOBALS.feed.recompute().await {
|
||||||
|
tracing::error!("{}", e);
|
||||||
|
}
|
||||||
|
*GLOBALS.feed.last_computed.write() = now;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn recompute(&self) -> Result<(), Error> {
|
pub async fn recompute(&self) -> Result<(), Error> {
|
||||||
let settings = GLOBALS.settings.read().await.clone();
|
let settings = GLOBALS.settings.read().await.clone();
|
||||||
*self.interval_ms.write() = settings.feed_recompute_interval_ms;
|
*self.interval_ms.write() = settings.feed_recompute_interval_ms;
|
||||||
|
Loading…
Reference in New Issue
Block a user