mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
remove async dependencies
This commit is contained in:
parent
e2b0cd6b0d
commit
b187f36028
33 changed files with 120 additions and 129 deletions
|
|
@ -10,11 +10,11 @@ use memory::Memory;
|
|||
use r2d2::Pool;
|
||||
use r2d2_sqlite::SqliteConnectionManager;
|
||||
use sqlite::Transaction;
|
||||
use std::sync::RwLock;
|
||||
use std::cell::RefCell;
|
||||
|
||||
pub struct Bookmark {
|
||||
database: Database, // permanent storage
|
||||
memory: RwLock<Memory>, // fast search index
|
||||
database: Database, // permanent storage
|
||||
memory: RefCell<Memory>, // fast search index
|
||||
}
|
||||
|
||||
impl Bookmark {
|
||||
|
|
@ -24,11 +24,11 @@ impl Bookmark {
|
|||
pub fn build(database_pool: &Pool<SqliteConnectionManager>, profile_id: i64) -> Result<Self> {
|
||||
// Init children components
|
||||
let database = Database::new(database_pool, profile_id);
|
||||
let memory = RwLock::new(Memory::new());
|
||||
let memory = RefCell::new(Memory::new());
|
||||
|
||||
// Build initial index
|
||||
{
|
||||
let mut memory = memory.write().unwrap();
|
||||
let mut memory = memory.borrow_mut();
|
||||
for item in database.records(None, None)? {
|
||||
memory.add(item);
|
||||
}
|
||||
|
|
@ -43,7 +43,7 @@ impl Bookmark {
|
|||
/// Toggle bookmark in `database` and `memory` index
|
||||
/// * return `true` on bookmark create, `false` on delete
|
||||
pub fn toggle(&self, request: &str, title: Option<&str>) -> Result<bool> {
|
||||
let mut memory = self.memory.write().unwrap();
|
||||
let mut memory = self.memory.borrow_mut();
|
||||
Ok(match memory.delete_by_request(request) {
|
||||
Some(item) => {
|
||||
self.database.delete(item.id)?;
|
||||
|
|
@ -64,20 +64,17 @@ impl Bookmark {
|
|||
|
||||
/// Check `request` exists in the memory index
|
||||
pub fn is_match_request(&self, request: &str) -> bool {
|
||||
self.memory.write().unwrap().is_match_request(request)
|
||||
self.memory.borrow_mut().is_match_request(request)
|
||||
}
|
||||
|
||||
/// Find Items match `request`
|
||||
pub fn contains_request(&self, request: &str, limit: Option<usize>) -> Vec<Item> {
|
||||
self.memory
|
||||
.write()
|
||||
.unwrap()
|
||||
.contains_request(request, limit)
|
||||
self.memory.borrow_mut().contains_request(request, limit)
|
||||
}
|
||||
|
||||
/// Get recent Items vector from `memory`, sorted by `ID` DESC
|
||||
pub fn recent(&self, limit: Option<usize>) -> Vec<Item> {
|
||||
self.memory.read().unwrap().recent(limit)
|
||||
self.memory.borrow().recent(limit)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue