mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-08-26 14:32:26 +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() {
|
if !items.is_empty() {
|
||||||
for item in items
|
for item in items
|
||||||
.into_iter()
|
.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 subtitle = highlight(&item.request, &query);
|
||||||
let title = match item.title {
|
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)]
|
#[derive(Clone)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
@ -9,12 +12,12 @@ pub struct Item {
|
|||||||
/// Some history items may contain title (e.g. gemtext documents and system tabs)
|
/// 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
|
/// * used as the additional criteria for search in the navbar suggestions widget
|
||||||
pub title: Option<GString>,
|
pub title: Option<GString>,
|
||||||
/// Collect opened count with event time
|
/// Collect `Item` open events
|
||||||
/// * used for sort order search results in the navbar suggestions widget
|
/// * used for sort order search results in the navbar suggestions widget and history page
|
||||||
pub opened: Vec<DateTime>,
|
pub opened: Event,
|
||||||
/// Collect tab closed count with event time
|
/// Collect `Item` close events
|
||||||
/// * used in recently closed pages menu
|
/// * used in recently closed pages menu and history page
|
||||||
pub closed: Vec<DateTime>,
|
pub closed: Option<Event>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Item {
|
impl Item {
|
||||||
@ -25,24 +28,21 @@ impl Item {
|
|||||||
id: None,
|
id: None,
|
||||||
request,
|
request,
|
||||||
title,
|
title,
|
||||||
opened: vec![now()],
|
opened: Event::new(),
|
||||||
closed: vec![],
|
closed: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|
||||||
pub fn open(&mut self) {
|
pub fn open(&mut self) {
|
||||||
self.opened.push(now())
|
self.opened.pulse()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(&mut self) {
|
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
|
for (i, item) in self
|
||||||
.0
|
.0
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|x| !x.closed.is_empty())
|
.filter(|x| x.closed.is_some())
|
||||||
.sorted_by(|a, b| Ord::cmp(&b.closed.last(), &a.closed.last()))
|
.sorted_by(|a, b| {
|
||||||
|
Ord::cmp(
|
||||||
|
&b.closed.as_ref().unwrap().time,
|
||||||
|
&a.closed.as_ref().unwrap().time,
|
||||||
|
)
|
||||||
|
})
|
||||||
.enumerate()
|
.enumerate()
|
||||||
{
|
{
|
||||||
if limit.is_some_and(|l| i > l) {
|
if limit.is_some_and(|l| i > l) {
|
||||||
@ -66,7 +71,7 @@ impl Memory {
|
|||||||
for (i, item) in self
|
for (i, item) in self
|
||||||
.0
|
.0
|
||||||
.iter()
|
.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()
|
.enumerate()
|
||||||
{
|
{
|
||||||
if limit.is_some_and(|l| i > l) {
|
if limit.is_some_and(|l| i > l) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user