Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove database flush #575

Merged
merged 2 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ To decouple the `Wallet` from the `Blockchain` we've made major changes:
- Stop making a request for the block height when calling `Wallet:new`.
- Added `SyncOptions` to capture extra (future) arguments to `Wallet::sync`.
- Removed `max_addresses` sync parameter which determined how many addresses to cache before syncing since this can just be done with `ensure_addresses_cached`.
- remove `flush` method from the `Database` trait.

## [v0.16.1] - [v0.16.0]

Expand Down
4 changes: 0 additions & 4 deletions src/database/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ impl Database for AnyDatabase {
fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error> {
impl_inner_method!(AnyDatabase, self, increment_last_index, keychain)
}

fn flush(&mut self) -> Result<(), Error> {
impl_inner_method!(AnyDatabase, self, flush)
}
}

impl BatchOperations for AnyBatch {
Expand Down
44 changes: 13 additions & 31 deletions src/database/keyvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,9 @@ macro_rules! impl_batch_operations {
fn del_last_index(&mut self, keychain: KeychainKind) -> Result<Option<u32>, Error> {
let key = MapKey::LastIndex(keychain).as_map_key();
let res = self.remove(key);
let res = $process_delete!(res);

match res {
None => Ok(None),
Some(b) => {
let array: [u8; 4] = b.as_ref().try_into().map_err(|_| Error::InvalidU32Bytes(b.to_vec()))?;
let val = u32::from_be_bytes(array);
Ok(Some(val))
}
}
$process_delete!(res)
.map(ivec_to_u32)
.transpose()
}

fn del_sync_time(&mut self) -> Result<Option<SyncTime>, Error> {
Expand Down Expand Up @@ -357,16 +350,7 @@ impl Database for Tree {

fn get_last_index(&self, keychain: KeychainKind) -> Result<Option<u32>, Error> {
let key = MapKey::LastIndex(keychain).as_map_key();
self.get(key)?
.map(|b| -> Result<_, Error> {
let array: [u8; 4] = b
.as_ref()
.try_into()
.map_err(|_| Error::InvalidU32Bytes(b.to_vec()))?;
let val = u32::from_be_bytes(array);
Ok(val)
})
.transpose()
self.get(key)?.map(ivec_to_u32).transpose()
}

fn get_sync_time(&self) -> Result<Option<SyncTime>, Error> {
Expand All @@ -393,19 +377,17 @@ impl Database for Tree {

Some(new.to_be_bytes().to_vec())
})?
.map_or(Ok(0), |b| -> Result<_, Error> {
let array: [u8; 4] = b
.as_ref()
.try_into()
.map_err(|_| Error::InvalidU32Bytes(b.to_vec()))?;
let val = u32::from_be_bytes(array);
Ok(val)
})
.map_or(Ok(0), ivec_to_u32)
}
}

fn flush(&mut self) -> Result<(), Error> {
Ok(Tree::flush(self).map(|_| ())?)
}
fn ivec_to_u32(b: sled::IVec) -> Result<u32, Error> {
let array: [u8; 4] = b
.as_ref()
.try_into()
.map_err(|_| Error::InvalidU32Bytes(b.to_vec()))?;
let val = u32::from_be_bytes(array);
Ok(val)
}

impl BatchDatabase for Tree {
Expand Down
4 changes: 0 additions & 4 deletions src/database/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,6 @@ impl Database for MemoryDatabase {

Ok(*value)
}

fn flush(&mut self) -> Result<(), Error> {
Ok(())
}
}

impl BatchDatabase for MemoryDatabase {
Expand Down
7 changes: 0 additions & 7 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,6 @@ pub trait Database: BatchOperations {
///
/// It should insert and return `0` if not present in the database
fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error>;

#[deprecated(
since = "0.18.0",
note = "The flush function is only needed for the sled database on mobile, instead for mobile use the sqlite database."
)]
/// Force changes to be written to disk
fn flush(&mut self) -> Result<(), Error>;
}

/// Trait for a database that supports batch operations
Expand Down
4 changes: 0 additions & 4 deletions src/database/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,10 +891,6 @@ impl Database for SqliteDatabase {
}
}
}

fn flush(&mut self) -> Result<(), Error> {
Ok(())
}
}

impl BatchDatabase for SqliteDatabase {
Expand Down