Prepare function drop_uncached_events() to sync NoteData cache with GLOBALS.events cache

This commit is contained in:
Nethanja Focking 2023-04-06 08:09:03 -06:00
parent 0f544f28fa
commit 9ac3d7803c
3 changed files with 16 additions and 5 deletions

View File

@ -52,11 +52,9 @@ impl Events {
}
}
/*
pub fn contains_key(&self, id: &Id) -> bool {
self.events.contains_key(id)
}
*/
pub fn get(&self, id: &Id) -> Option<Event> {
self.events.get(id).map(|e| e.value().to_owned())

View File

@ -64,6 +64,7 @@ pub(super) fn render_note(
if let Some(note_ref) = app.notes.try_update_and_get(&id) {
// FIXME respect app.settings.show_long_form on reposts
// FIXME drop the cached notes on recompute
if let Ok(note_data) = note_ref.try_borrow() {
if note_data.author.muted > 0 {

View File

@ -3,8 +3,9 @@ use crate::{
globals::{Globals, GLOBALS},
people::DbPerson,
};
use dashmap::DashMap;
use nostr_types::{Event, EventDelegation, EventKind, Id, NostrBech32, PublicKeyHex, Tag};
use std::{cell::RefCell, collections::HashMap, rc::Rc};
use std::{cell::RefCell, rc::Rc};
#[derive(PartialEq)]
pub(super) enum RepostType {
@ -192,13 +193,24 @@ impl NoteData {
/// a 'note' is a processed event
pub struct Notes {
notes: HashMap<Id, Rc<RefCell<NoteData>>>,
notes: DashMap<Id, Rc<RefCell<NoteData>>>,
}
impl Notes {
pub fn new() -> Notes {
Notes {
notes: HashMap::new(),
notes: DashMap::new(),
}
}
/// Drop NoteData objects that do not have a
/// correlated event in the event cache
pub(super) fn drop_uncached_events(&mut self) {
for note in self.notes.iter_mut() {
if !GLOBALS.events.contains_key(&note.key()) {
// drop the NoteData
self.notes.remove(note.key());
}
}
}