-
Notifications
You must be signed in to change notification settings - Fork 773
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
Blockchain: refactor: Add abstract DB operation, let DB manage the implementation of this OP + make DB handle Cache #927
Conversation
Codecov Report
Flags with carried forward coverage won't be shown. Click here to find out more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, looks really clean!
I'd like an additional review here before merging this, since it changes the internal stuff a lot, rather have some more eyes on it 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to echo @ryanio's review this looks great! Really nice. 🎉
Couple questions, that's it.
async batch(ops: DatabaseOperation[]) { | ||
const convertedOps: DBOp[] = ops.map((op) => op.baseDBOp) | ||
// update the current cache for each operation | ||
ops.map((op) => op.updateCache(this._cache)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a substantive change (a bug fix)? (Am just requesting more info - I don't know this lib very well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR does not fix any bugs. Previously, these cache operations were all handled in index.ts
of blockchain, but now they are handled within these DatabaseOperation
s every time we do a batch request of these ops
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-approving 🙂
I will wait until @holgerd77 also gives this a look (don't worry, not in a hurry). Have to rebase this anyways, so that will need a re-approval anyways 😛 |
07c5f70
to
9f8ff31
Compare
Rebased this. |
I would perceive this as cleaner and less redundant if we remove the
Prefixes on classes (e.g.
And so on. |
Yeah, after letting the code take a bit its effect I would re-state that I find this renaming thing pretty important, this otherwise leads to very long lines which are somewhat hard to read. ops.push(DatabaseOperation.del(DatabaseOperationTarget.Header, { blockHash, blockNumber })) ops.push(DBOps.del(DBTarget.Header, { blockHash, blockNumber })) Just doing a live-test here on myself with the two lines from above to see how I perceive readability. I think I would actually also tend to do the Apart from these cosmetics this looks really good! Great that this library gets such a shift on readability! 😄 |
Hi @holgerd77, thanks for your suggestions! You are absolutely right about the names of these files and the class names, I will edit those. You are also right about the names of these newly introduced helpers, I honestly had a struggle myself to come up with a name for them which was both short and descriptive 😅 . |
9f8ff31
to
d747941
Compare
OK, in d747941 I have renamed DatabaseOperation -> DBOp, the original exported Ready for re-review! @holgerd77 Reviewing d747941 should be sufficient here. Have to squash here, seems I did something wrong on the rebase. |
d747941
to
a673fdc
Compare
blockchain: include new DB changes blockchain: lint blockchain: fix tests blockchain: lint
a673fdc
to
57bcd88
Compare
Rebased this on top of #929 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have done some more renamings, this looks great, thanks Jochem! 😄 👍
Tx test CI run was failing on last run, tests itself are passing though, this is just a browser timing issue and also highly unlikely to be related with the changes here, since tx has no block or blockchain dependencies.
We might want to observe this a bit, but I will merge here for now.
Thanks for these extra renames 👍 Tx and Block sometimes indeed seem to timeout; if you rerun the CI then it usually passes. |
Blockchains
index.ts
used to do a lot of DB-like operations, like calculating the keys and updating the cache. This is now different; adatabaseOperation
factory is added, which describes these operations. Also, all DB operations are moved into aDB
folder. This is an internal refactor and does not change any external behavior. Cherry-picked from #895.