mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
implement search providers memory cache
This commit is contained in:
parent
2df86b27ab
commit
3613db8b1c
4 changed files with 131 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use sqlite::{Connection, Error, Transaction};
|
||||
use std::{rc::Rc, sync::RwLock};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Row {
|
||||
pub id: i64,
|
||||
//pub profile_id: i64,
|
||||
|
|
|
|||
16
src/profile/search/error.rs
Normal file
16
src/profile/search/error.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use std::fmt::{Display, Formatter, Result};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Database(sqlite::Error),
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match self {
|
||||
Self::Database(e) => {
|
||||
write!(f, "Database error: {e}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/profile/search/memory.rs
Normal file
39
src/profile/search/memory.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use super::database::Row;
|
||||
use std::cell::RefCell;
|
||||
|
||||
/// Reduce disk usage by cache Bookmarks index in memory
|
||||
pub struct Memory {
|
||||
index: RefCell<Vec<Row>>,
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn init() -> Self {
|
||||
Self {
|
||||
index: RefCell::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Add new record
|
||||
pub fn push(&self, id: i64, query: String, is_default: bool) {
|
||||
self.index.borrow_mut().push(Row {
|
||||
id,
|
||||
query,
|
||||
is_default,
|
||||
})
|
||||
}
|
||||
|
||||
/// Clear all records
|
||||
pub fn clear(&self) {
|
||||
self.index.borrow_mut().clear()
|
||||
}
|
||||
|
||||
/// Get record by `ID`
|
||||
pub fn records(&self) -> Vec<Row> {
|
||||
self.index.borrow().clone()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue