implement recent bookmarks menu item

This commit is contained in:
yggverse 2025-01-12 00:38:22 +02:00
parent c335207b28
commit 9e86e9b29f
13 changed files with 155 additions and 60 deletions

View file

@ -11,8 +11,8 @@ use sqlite::{Connection, Transaction};
use std::{rc::Rc, sync::RwLock};
pub struct Bookmark {
database: Rc<Database>, // permanent storage
memory: Rc<Memory>, // fast search index
pub database: Rc<Database>, // permanent storage
pub memory: Rc<Memory>, // fast search index
}
impl Bookmark {

View file

@ -1,6 +1,7 @@
mod error;
use error::Error;
use itertools::Itertools;
use std::{cell::RefCell, collections::HashMap};
/// Reduce disk usage by cache Bookmarks index in memory
@ -54,4 +55,24 @@ impl Memory {
None => Err(Error::Unexpected), // @TODO
}
}
/// Get recent requests vector sorted DESC by `ID`
pub fn recent(&self, limit: usize) -> Vec<String> {
let mut recent: Vec<String> = Vec::new();
for (request, _) in self
.index
.borrow()
.iter()
.sorted_by(|a, b| Ord::cmp(&b.1, &a.1))
.take(limit)
{
recent.push(request.to_string())
}
recent
}
/// Get total records in memory pool
pub fn total(&self) -> usize {
self.index.borrow().len()
}
}