notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

unknowns.rs (2040B)


      1 /*
      2 use crate::{timeline::TimelineCache, Result};
      3 use nostrdb::{Ndb, NoteKey, Transaction};
      4 use notedeck::{CachedNote, NoteCache, UnknownIds};
      5 use tracing::error;
      6 
      7 pub fn update_from_columns(
      8     txn: &Transaction,
      9     unknown_ids: &mut UnknownIds,
     10     timeline_cache: &TimelineCache,
     11     ndb: &Ndb,
     12     note_cache: &mut NoteCache,
     13 ) -> bool {
     14     let before = unknown_ids.ids_iter().len();
     15     if let Err(e) = get_unknown_ids(txn, unknown_ids, timeline_cache, ndb, note_cache) {
     16         error!("UnknownIds::update {e}");
     17     }
     18     let after = unknown_ids.ids_iter().len();
     19 
     20     if before != after {
     21         unknown_ids.mark_updated();
     22         true
     23     } else {
     24         false
     25     }
     26 }
     27 
     28 #[profiling::function]
     29 pub fn get_unknown_ids(
     30     txn: &Transaction,
     31     unknown_ids: &mut UnknownIds,
     32     timeline_cache: &TimelineCache,
     33     ndb: &Ndb,
     34     note_cache: &mut NoteCache,
     35 ) -> Result<()> {
     36     let mut new_cached_notes: Vec<(NoteKey, CachedNote)> = vec![];
     37 
     38     for (_kind, timeline) in timeline_cache.timelines.iter() {
     39         for noteref in timeline.all_or_any_notes() {
     40             let note = ndb.get_note_by_key(txn, noteref.key)?;
     41             let note_key = note.key().unwrap();
     42             let cached_note = note_cache.cached_note(noteref.key);
     43             let cached_note = if let Some(cn) = cached_note {
     44                 cn.clone()
     45             } else {
     46                 let new_cached_note = CachedNote::new(&note);
     47                 new_cached_notes.push((note_key, new_cached_note.clone()));
     48                 new_cached_note
     49             };
     50 
     51             let _ = notedeck::get_unknown_note_ids(
     52                 ndb,
     53                 &cached_note,
     54                 txn,
     55                 &note,
     56                 unknown_ids.ids_mut(),
     57             );
     58         }
     59     }
     60 
     61     // This is mainly done to avoid the double mutable borrow that would happen
     62     // if we tried to update the note_cache mutably in the loop above
     63     for (note_key, note) in new_cached_notes {
     64         note_cache.cache_mut().insert(note_key, note);
     65     }
     66 
     67     Ok(())
     68 }
     69 */