fuel-core icon indicating copy to clipboard operation
fuel-core copied to clipboard

Some improvements during work with the database

Open xgreenx opened this issue 2 years ago • 2 comments

Use Option<&[u8]> instead of Option<Vec<u8>> in the iter_all of fuel_core::state::KeyValueStore. Also decide, do we really need usage of Option? If len is zero it is the same as None. Apply the same change for all upper functions.

image

Also there in the implementation of the iterator, we can avoid the copy of the slices into vectors. Also think about comment.

image

Minor improvement in Database::insert: image

To use the same naming across the project in Database::exists: image

xgreenx avatar Sep 14 '22 17:09 xgreenx

If len is zero it is the same as None

Not necessarily, there is value in being able to distinguish between empty values and non-existent ones.

Voxelot avatar Sep 14 '22 21:09 Voxelot

@Voxelot What do you think about renaming all Database's methods by underscore? To highlight that they are internal methods, and you need to work with StorageMutate and StorageInspect.

  • Database::insert -> Database::_insert
  • Database::remove -> Database::_remove
  • Database::get -> Database::_get
  • Database::exists -> Database::_contains_key
  • Database::iter_all -> Database::_iter_all

xgreenx avatar Sep 14 '22 22:09 xgreenx

Hey @xgreenx & @Voxelot, is the issue still open. i'd like to work on it :))

AliJafriETH avatar Dec 26 '22 17:12 AliJafriETH

There is in progress PR https://github.com/FuelLabs/fuel-core/pull/643 that is blocked by refactoring https://github.com/FuelLabs/fuel-core/issues/809. The change is almost ready, so it is better to select another issue=D

xgreenx avatar Dec 26 '22 17:12 xgreenx