Maintain GLOBALS.current_bookmarks as a resolved Vec<Id> via a periodic task

This commit is contained in:
Mike Dilger 2024-07-04 10:43:52 +12:00
parent 8867cedc64
commit b38fa8b87b
2 changed files with 12 additions and 0 deletions

View File

@ -157,6 +157,9 @@ pub struct Globals {
/// Bookmarks
pub bookmarks: PRwLock<BookmarkList>,
/// Current bookmarks, resolved into a Vec<Id> (updated by tasks)
pub current_bookmarks: PRwLock<Vec<Id>>,
}
lazy_static! {
@ -226,6 +229,7 @@ lazy_static! {
pending: Pending::new(),
loading_more: AtomicUsize::new(0),
bookmarks: PRwLock::new(BookmarkList::empty()),
current_bookmarks: PRwLock::new(Vec::new()),
}
};
}

View File

@ -75,4 +75,12 @@ async fn do_general_tasks(tick: usize) {
GLOBALS.unread_dms.store(unread, Ordering::Relaxed);
}
}
// Update current bookmarks from bookmarks (every 2 seconds)
if tick % 2 == 0 {
match GLOBALS.bookmarks.read().get_bookmark_feed() {
Ok(feed) => *GLOBALS.current_bookmarks.write() = feed,
Err(e) => tracing::error!("{:?}", e),
}
}
}