-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Minor improvement Chelonia #1618
Merged
taoeffect
merged 13 commits into
master
from
1599-postpublish-should-be-given-message-actually-published
Jun 3, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
de281ec
feat: optimized code using
Silver-IT bd4245f
feat: renamed eventsSince to eventsAfter
Silver-IT d2e5543
feat: return updated GIMessage object after publishEvent
Silver-IT b44e1f6
feat: updated backend test case for updated publishEvent function
Silver-IT 22eb7d4
feat: rename streamEntriesSince to streamEntriesAfter in backend
Silver-IT e50ae98
feat: validate latest hash when sync contract
Silver-IT 08078c6
Merge branch 'master' into 1599-postpublish-should-be-given-message-a…
Silver-IT 8b882e0
chore: removed unneessary comment
Silver-IT 2b54c2a
feat: cypress version upgraded from 7.7.0 to 9.7.0
Silver-IT f6b3353
chore: downgrade cypress for the performance issue
Silver-IT d3a4c17
chore: revert package-lock.json
Silver-IT e7e537b
chore: better naming
Silver-IT 2c753de
feat: improve comments
Silver-IT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,7 @@ export default (sbp('sbp/selectors/register', { | |
} | ||
}) | ||
if (r.ok) { | ||
return r.text() | ||
return entry | ||
} | ||
if (r.status === 409) { | ||
if (attempt + 1 > maxAttempts) { | ||
|
@@ -222,8 +222,8 @@ export default (sbp('sbp/selectors/register', { | |
} | ||
if (processOp && !config.skipProcessing) { | ||
opFns[opT](opV) | ||
config.postOp && config.postOp(message, state) | ||
config[`postOp_${opT}`] && config[`postOp_${opT}`](message, state) | ||
config.postOp?.(message, state) | ||
config[`postOp_${opT}`]?.(message, state) | ||
Comment on lines
+225
to
+226
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beautiful 👍 |
||
} | ||
}, | ||
'chelonia/private/in/enqueueHandleEvent': function (event: GIMessage) { | ||
|
@@ -253,7 +253,21 @@ export default (sbp('sbp/selectors/register', { | |
if (latest !== recent) { | ||
console.debug(`[chelonia] Synchronizing Contract ${contractID}: our recent was ${recent || 'undefined'} but the latest is ${latest}`) | ||
// TODO: fetch events from localStorage instead of server if we have them | ||
const events = await sbp('chelonia/out/eventsSince', contractID, recent || contractID) | ||
const events = await sbp('chelonia/out/eventsAfter', contractID, recent || contractID) | ||
// Sanity check: verify event with latest hash exists in list of events | ||
// TODO: using findLastIndex, it will be more clean but it needs Cypress 9.7+ which has bad performance | ||
// https://docs.cypress.io/guides/references/changelog#9-7-0 | ||
// https://github.com/cypress-io/cypress/issues/22868 | ||
let latestHashFound = false | ||
for (let i = events.length - 1; i >= 0; i--) { | ||
if (GIMessage.deserialize(events[i]).hash() === latest) { | ||
latestHashFound = true | ||
break | ||
} | ||
} | ||
if (!latestHashFound) { | ||
throw new ChelErrorUnrecoverable(`expected hash ${latest} in list of events for contract ${contractID}`) | ||
} | ||
// remove the first element in cases where we are not getting the contract for the first time | ||
state.contracts[contractID] && events.shift() | ||
for (let i = 0; i < events.length; i++) { | ||
|
@@ -281,7 +295,7 @@ export default (sbp('sbp/selectors/register', { | |
// Errors in mutations result in ignored messages | ||
// Errors in side effects result in dropped messages to be reprocessed | ||
try { | ||
preHandleEvent && await preHandleEvent(message) | ||
await preHandleEvent?.(message) | ||
// verify we're expecting to hear from this contract | ||
if (!state.pending.includes(contractID) && !state.contracts[contractID]) { | ||
console.warn(`[chelonia] WARN: ignoring unexpected event ${message.description()}:`, message.serialize()) | ||
|
@@ -327,7 +341,7 @@ export default (sbp('sbp/selectors/register', { | |
this.config.hooks.sideEffectError?.(e, message) | ||
} | ||
try { | ||
postHandleEvent && await postHandleEvent(message) | ||
await postHandleEvent?.(message) | ||
sbp('okTurtles.events/emit', hash, contractID, message) | ||
sbp('okTurtles.events/emit', EVENT_HANDLED, contractID, message) | ||
} catch (e) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice, I love this simplification of using
?.
and how you added it to many places in the code that needs it!