mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
add memory cache for auth index
This commit is contained in:
parent
9530c37c59
commit
d9bf85884b
5 changed files with 96 additions and 10 deletions
|
|
@ -1,13 +1,16 @@
|
|||
mod database;
|
||||
mod memory;
|
||||
|
||||
use database::Database;
|
||||
use memory::Memory;
|
||||
|
||||
use sqlite::{Connection, Transaction};
|
||||
use std::{rc::Rc, sync::RwLock};
|
||||
|
||||
/// API for `profile_identity_gemini_id` + `url` auth pairs operations
|
||||
pub struct Auth {
|
||||
pub database: Rc<Database>,
|
||||
// pub database: Rc<Database>,
|
||||
pub memory: Rc<Memory>,
|
||||
}
|
||||
|
||||
impl Auth {
|
||||
|
|
@ -15,8 +18,31 @@ impl Auth {
|
|||
|
||||
/// Create new `Self`
|
||||
pub fn new(connection: Rc<RwLock<Connection>>) -> Self {
|
||||
// Init children components
|
||||
let database = Rc::new(Database::new(connection));
|
||||
let memory = Rc::new(Memory::new());
|
||||
|
||||
// Build initial index
|
||||
match database.records(None) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
if record.is_active {
|
||||
if memory
|
||||
.add(record.url, record.profile_identity_gemini_id)
|
||||
.is_err()
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(reason) => todo!("{reason}"),
|
||||
}
|
||||
|
||||
// Return new `Self`
|
||||
Self {
|
||||
database: Rc::new(Database::new(connection)),
|
||||
// database,
|
||||
memory,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue