remove direct memory access

This commit is contained in:
yggverse 2025-03-14 12:51:33 +02:00
parent 33369e31ea
commit 19a07cdf1d
32 changed files with 112 additions and 111 deletions

View file

@ -1,9 +1,9 @@
use super::database::Row;
use std::cell::RefCell;
use std::sync::RwLock;
/// Reduce disk usage by cache Bookmarks index in memory
pub struct Memory {
index: RefCell<Vec<Row>>,
index: RwLock<Vec<Row>>,
}
impl Memory {
@ -12,7 +12,7 @@ impl Memory {
/// Create new `Self`
pub fn init() -> Self {
Self {
index: RefCell::new(Vec::new()),
index: RwLock::new(Vec::new()),
}
}
@ -20,7 +20,7 @@ impl Memory {
/// Add new record
pub fn push(&self, id: i64, query: String, is_default: bool) {
self.index.borrow_mut().push(Row {
self.index.write().unwrap().push(Row {
id,
query,
is_default,
@ -29,19 +29,19 @@ impl Memory {
/// Clear all records
pub fn clear(&self) {
self.index.borrow_mut().clear()
self.index.write().unwrap().clear()
}
// Getters
/// Get all records
pub fn records(&self) -> Vec<Row> {
self.index.borrow().clone()
self.index.read().unwrap().clone()
}
/// Get all records
pub fn default(&self) -> Option<Row> {
for record in self.index.borrow().iter() {
for record in self.index.read().unwrap().iter() {
if record.is_default {
return Some(record.clone());
}