mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
replace vector collection with event snap for performance reasons (much detailed history logs not planned)
This commit is contained in:
parent
ce2b02569d
commit
11fecd9cf1
@ -161,7 +161,7 @@ impl Suggestion {
|
||||
if !items.is_empty() {
|
||||
for item in items
|
||||
.into_iter()
|
||||
.sorted_by(|a, b| Ord::cmp(&b.opened.len(), &a.opened.len()))
|
||||
.sorted_by(|a, b| Ord::cmp(&b.opened.count, &a.opened.count))
|
||||
{
|
||||
let subtitle = highlight(&item.request, &query);
|
||||
let title = match item.title {
|
||||
|
@ -1,4 +1,7 @@
|
||||
use gtk::glib::{DateTime, GString};
|
||||
mod event;
|
||||
|
||||
use event::Event;
|
||||
use gtk::glib::GString;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Item {
|
||||
@ -9,12 +12,12 @@ pub struct Item {
|
||||
/// Some history items may contain title (e.g. gemtext documents and system tabs)
|
||||
/// * used as the additional criteria for search in the navbar suggestions widget
|
||||
pub title: Option<GString>,
|
||||
/// Collect opened count with event time
|
||||
/// * used for sort order search results in the navbar suggestions widget
|
||||
pub opened: Vec<DateTime>,
|
||||
/// Collect tab closed count with event time
|
||||
/// * used in recently closed pages menu
|
||||
pub closed: Vec<DateTime>,
|
||||
/// Collect `Item` open events
|
||||
/// * used for sort order search results in the navbar suggestions widget and history page
|
||||
pub opened: Event,
|
||||
/// Collect `Item` close events
|
||||
/// * used in recently closed pages menu and history page
|
||||
pub closed: Option<Event>,
|
||||
}
|
||||
|
||||
impl Item {
|
||||
@ -25,24 +28,21 @@ impl Item {
|
||||
id: None,
|
||||
request,
|
||||
title,
|
||||
opened: vec![now()],
|
||||
closed: vec![],
|
||||
opened: Event::new(),
|
||||
closed: None,
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
pub fn open(&mut self) {
|
||||
self.opened.push(now())
|
||||
self.opened.pulse()
|
||||
}
|
||||
|
||||
pub fn close(&mut self) {
|
||||
self.closed.push(now())
|
||||
match self.closed {
|
||||
Some(ref mut closed) => closed.pulse(),
|
||||
None => self.closed = Some(Event::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tools
|
||||
|
||||
fn now() -> DateTime {
|
||||
DateTime::now_local().unwrap()
|
||||
}
|
||||
|
37
src/profile/history/item/event.rs
Normal file
37
src/profile/history/item/event.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use gtk::glib::DateTime;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Event {
|
||||
pub time: DateTime,
|
||||
pub count: usize,
|
||||
}
|
||||
|
||||
impl Event {
|
||||
// Constructors
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
time: now(),
|
||||
count: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
pub fn pulse(&mut self) {
|
||||
self.time = now();
|
||||
self.count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Event {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
// Tools
|
||||
|
||||
fn now() -> DateTime {
|
||||
DateTime::now_local().unwrap()
|
||||
}
|
@ -48,8 +48,13 @@ impl Memory {
|
||||
for (i, item) in self
|
||||
.0
|
||||
.iter()
|
||||
.filter(|x| !x.closed.is_empty())
|
||||
.sorted_by(|a, b| Ord::cmp(&b.closed.last(), &a.closed.last()))
|
||||
.filter(|x| x.closed.is_some())
|
||||
.sorted_by(|a, b| {
|
||||
Ord::cmp(
|
||||
&b.closed.as_ref().unwrap().time,
|
||||
&a.closed.as_ref().unwrap().time,
|
||||
)
|
||||
})
|
||||
.enumerate()
|
||||
{
|
||||
if limit.is_some_and(|l| i > l) {
|
||||
@ -66,7 +71,7 @@ impl Memory {
|
||||
for (i, item) in self
|
||||
.0
|
||||
.iter()
|
||||
.sorted_by(|a, b| Ord::cmp(&b.opened.last(), &a.opened.last()))
|
||||
.sorted_by(|a, b| Ord::cmp(&b.opened.time, &a.opened.time))
|
||||
.enumerate()
|
||||
{
|
||||
if limit.is_some_and(|l| i > l) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user