mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
reorganize clone semantics, implement recently closed tabs history
This commit is contained in:
parent
3682b5bf3f
commit
ba68019614
17 changed files with 176 additions and 52 deletions
|
|
@ -56,7 +56,7 @@ pub fn select(
|
|||
WHERE `profile_id` = ? AND `request` LIKE ?",
|
||||
)?;
|
||||
|
||||
let result = stmt.query_map((profile_id, request.unwrap_or("%")), |row| {
|
||||
let result = stmt.query_map((profile_id, request.unwrap_or("%".to_string())), |row| {
|
||||
Ok(Table {
|
||||
id: row.get(0)?,
|
||||
profile_id: row.get(1)?,
|
||||
|
|
|
|||
24
src/profile/history/memory.rs
Normal file
24
src/profile/history/memory.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
mod closed;
|
||||
use closed::Closed;
|
||||
|
||||
/// Reduce disk usage by cache Bookmarks index in memory
|
||||
pub struct Memory {
|
||||
pub closed: Closed,
|
||||
}
|
||||
|
||||
impl Default for Memory {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
closed: Closed::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
53
src/profile/history/memory/closed.rs
Normal file
53
src/profile/history/memory/closed.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
use gtk::glib::GString;
|
||||
use itertools::Itertools;
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
|
||||
/// Reduce disk usage by cache Bookmarks index in memory
|
||||
pub struct Closed {
|
||||
index: RefCell<HashMap<GString, i64>>,
|
||||
}
|
||||
|
||||
impl Default for Closed {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Closed {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
index: RefCell::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Add new record
|
||||
/// * replace with new one if the record already exist
|
||||
pub fn add(&self, request: GString, unix_timestamp: i64) {
|
||||
self.index.borrow_mut().insert(request, unix_timestamp);
|
||||
}
|
||||
|
||||
/// Get recent requests vector sorted by `ID` DESC
|
||||
pub fn recent(&self, limit: usize) -> Vec<GString> {
|
||||
let mut recent: Vec<GString> = Vec::new();
|
||||
for (request, _) in self
|
||||
.index
|
||||
.borrow()
|
||||
.iter()
|
||||
.sorted_by(|a, b| Ord::cmp(&b.1, &a.1))
|
||||
.take(limit)
|
||||
{
|
||||
recent.push(request.clone())
|
||||
}
|
||||
recent
|
||||
}
|
||||
|
||||
/// Get records total
|
||||
pub fn total(&self) -> usize {
|
||||
self.index.borrow().len()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue