mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
feat(vault): add bulk new record method on storage abstraction
Instead of syncing for each new record, new_records() only syncs: - when it's writing an entry that has index multiple of 10 - when it's the last packet in sequence
This commit is contained in:
parent
2e50699c82
commit
a594342d03
1 changed files with 42 additions and 2 deletions
|
|
@ -92,6 +92,7 @@ impl Manager {
|
||||||
key_name: &str,
|
key_name: &str,
|
||||||
alloc_hint: Option<usize>,
|
alloc_hint: Option<usize>,
|
||||||
basis: Option<String>,
|
basis: Option<String>,
|
||||||
|
sync: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
match self.pddb.get(
|
match self.pddb.get(
|
||||||
dict,
|
dict,
|
||||||
|
|
@ -103,7 +104,10 @@ impl Manager {
|
||||||
Some(crate::basis_change),
|
Some(crate::basis_change),
|
||||||
) {
|
) {
|
||||||
Ok(mut data) => match data.write(payload) {
|
Ok(mut data) => match data.write(payload) {
|
||||||
Ok(_) => Ok(self.pddb.sync().unwrap_or(())),
|
Ok(_) => match sync {
|
||||||
|
true => Ok(self.pddb.sync().unwrap_or(())),
|
||||||
|
false => Ok(()),
|
||||||
|
},
|
||||||
Err(e) => Err(Error::IoError(e)),
|
Err(e) => Err(Error::IoError(e)),
|
||||||
},
|
},
|
||||||
Err(e) => Err(Error::IoError(e)),
|
Err(e) => Err(Error::IoError(e)),
|
||||||
|
|
@ -163,10 +167,46 @@ impl Manager {
|
||||||
&settings.dict,
|
&settings.dict,
|
||||||
&guid,
|
&guid,
|
||||||
settings.alloc_hint,
|
settings.alloc_hint,
|
||||||
basis,
|
basis.clone(),
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_records(
|
||||||
|
&mut self,
|
||||||
|
records: Vec<Box<dyn StorageContent>>,
|
||||||
|
basis: Option<String>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let mut precords = records.into_iter().peekable();
|
||||||
|
let mut current_idx = 0; // idk how to use peekable + enumerate
|
||||||
|
while let Some(record) = precords.next() {
|
||||||
|
let mut record = record;
|
||||||
|
let settings = record.settings();
|
||||||
|
record.set_ctime(utc_now().timestamp() as u64);
|
||||||
|
let serialized_record: Vec<u8> = record.to_vec();
|
||||||
|
let guid = self.gen_guid();
|
||||||
|
let should_sync = precords.peek().is_none() || current_idx % 10 == 0;
|
||||||
|
|
||||||
|
log::debug!("current_idx: {}, should_sync: {}, is_none: {}", current_idx, should_sync, precords.peek().is_none());
|
||||||
|
|
||||||
|
current_idx += 1;
|
||||||
|
|
||||||
|
match self.pddb_store(
|
||||||
|
&serialized_record,
|
||||||
|
&settings.dict,
|
||||||
|
&guid,
|
||||||
|
settings.alloc_hint,
|
||||||
|
basis.clone(),
|
||||||
|
should_sync,
|
||||||
|
) {
|
||||||
|
Ok(()) => continue,
|
||||||
|
Err(error) => return Err(error),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn all<T: StorageContent + std::default::Default>(
|
pub fn all<T: StorageContent + std::default::Default>(
|
||||||
&self,
|
&self,
|
||||||
kind: ContentKind,
|
kind: ContentKind,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue