-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement config definition caching within a transaction
Closes #21
- Loading branch information
Showing
6 changed files
with
508 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::kvs::kv::Key; | ||
use crate::sql::statements::DefineDatabaseStatement; | ||
use crate::sql::statements::DefineEventStatement; | ||
use crate::sql::statements::DefineFieldStatement; | ||
use crate::sql::statements::DefineIndexStatement; | ||
use crate::sql::statements::DefineLoginStatement; | ||
use crate::sql::statements::DefineNamespaceStatement; | ||
use crate::sql::statements::DefineScopeStatement; | ||
use crate::sql::statements::DefineTableStatement; | ||
use crate::sql::statements::DefineTokenStatement; | ||
use crate::sql::statements::LiveStatement; | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
#[derive(Clone)] | ||
pub enum Entry { | ||
Ns(Arc<DefineNamespaceStatement>), | ||
Db(Arc<DefineDatabaseStatement>), | ||
Tb(Arc<DefineTableStatement>), | ||
Nss(Arc<Vec<DefineNamespaceStatement>>), | ||
Nls(Arc<Vec<DefineLoginStatement>>), | ||
Nts(Arc<Vec<DefineTokenStatement>>), | ||
Dbs(Arc<Vec<DefineDatabaseStatement>>), | ||
Dls(Arc<Vec<DefineLoginStatement>>), | ||
Dts(Arc<Vec<DefineTokenStatement>>), | ||
Scs(Arc<Vec<DefineScopeStatement>>), | ||
Sts(Arc<Vec<DefineTokenStatement>>), | ||
Tbs(Arc<Vec<DefineTableStatement>>), | ||
Evs(Arc<Vec<DefineEventStatement>>), | ||
Fds(Arc<Vec<DefineFieldStatement>>), | ||
Ixs(Arc<Vec<DefineIndexStatement>>), | ||
Fts(Arc<Vec<DefineTableStatement>>), | ||
Lvs(Arc<Vec<LiveStatement>>), | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct Cache(pub HashMap<Key, Entry>); | ||
|
||
impl Cache { | ||
// Check if key exists | ||
pub fn exi(&mut self, key: &Key) -> bool { | ||
self.0.contains_key(key) | ||
} | ||
// Set a key in the cache | ||
pub fn set(&mut self, key: Key, val: Entry) { | ||
self.0.insert(key, val); | ||
} | ||
// get a key from the cache | ||
pub fn get(&mut self, key: &Key) -> Option<Entry> { | ||
self.0.get(key).cloned() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod cache; | ||
mod ds; | ||
mod file; | ||
mod ixdb; | ||
|
Oops, something went wrong.