mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
implement recent bookmarks menu item
This commit is contained in:
parent
c335207b28
commit
9e86e9b29f
13 changed files with 155 additions and 60 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue