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

Feature: PopDb - a caching system for pop-cli #92

Closed
wants to merge 8 commits into from
Closed

Conversation

weezy20
Copy link
Contributor

@weezy20 weezy20 commented Apr 1, 2024

PopDb is a caching system to cache recently used file paths with new commands like pop new parachain that are saved and used later when invoked with action commands like build, test, add etc. without explicit path args. Since PopDb is a generic key-value database, it maybe used for things beyond this, however this PR is just creating step 1 for PopDb.

Usage :

let popdb = PopDb::open_or_init();
// Set a key-value pair 
popdb.set_*(value);
// Fetch the same
popdb.get_*(key);

The preference for a file path is always in this order:

  1. User cli args
  2. Current working directory
  3. PopDb

Note: This preference is not possible because step 2 is always going to execute in any cargo project (see issue #91). Currently, the preference is 1 -> 3 -> 2 until a helper function is created to close #91.

Tasks (requires #91):
Implement PopDb cache look up in the following actions after is_parachain(current_dir()) or is_contract(current_dir()) checks have failed.

  • Build
  • Test
  • Up
  • Add ( unless add-pallet is merged this cannot be done )

Implement PopDb set in the following actions

  • new parachain
  • new contract
  • new pallet

Additional notes:

Error handling for PopDb is invisible to the user unless a LOG_TARGET of Debug or above is chosen. This is because errors involved with this system should have little to no effect on the user experience and are solely meant for developers of pop-cli. Fundamentally, there are two classes of errors that could happen:

  1. Errors opening the filesystem path /tmp/pop-cli-db
  2. cache misses or garbage values from cache.
    The first kind of errors are unlikely to happen, as usually, users are granted read-write permissions on /tmp. However the second kind of errors are a bit more subtle, and they require careful consideration and invalidation in case certain criteria are not met. One instance of this is invalid UTF-8 in --path. Storing Path as bytes involve lossy compression, and for invalid characters, String::from_utf8_lossy may yield unusable values.

Closes #9

@weezy20
Copy link
Contributor Author

weezy20 commented Apr 8, 2024

Note for reviewers: This cache has two sets of methods set_* and get_*. We set values when creating a new parachain, contract or a pallet, and the idea is to use these values on build | test | check etc actions if and only if current_dir() doesn't meet the criteria (#91). As a consequence, all the get_* methods are unused until #91 is closed.

@weezy20 weezy20 marked this pull request as ready for review April 8, 2024 07:53
@AlexD10S
Copy link
Collaborator

Looking good, but logic is not completed, should I move it into Draft again?

And just for curiosity, what other cases you have in mind for PopDb beyond keeping the file paths for build and test?

@weezy20 weezy20 closed this Apr 25, 2024
@weezy20 weezy20 deleted the w/9/cache branch June 27, 2024 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pop Build - Parachain/Contract cargo project detection on current working dir Cache to improve UX
2 participants