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

App state caching: improvements #313

Merged
merged 7 commits into from
May 28, 2019

Conversation

sohkai
Copy link
Contributor

@sohkai sohkai commented May 27, 2019

A couple of improvements to #297.

  • 956d722: Now that messenger: use defer() for observed requests to avoid dropping responses #305 is merged, we can use this.accounts() directly without worrying about the first emission being lost
  • d307e44: Supersedes Log errors thrown in reducer #301; the new Promise() also catches the case where reducer() throws synchronously, and the catchError() operator allows us to log and re-throw the error
    • To be on the safe side, opted to re-throw the error and end the store() stream for now, rather than silently returning the previous state and continuing the reducing
  • b451ece: Allow any state reduced from past events to be propagated as the current state, now that the cached state is kept in a separate key
    • In the future, we may want to completely move the state to be in-memory, since now we're effectively using double the storage (state and cache representations of the app's reduced state)

@sohkai sohkai requested a review from 2color May 27, 2019 21:50
@sohkai sohkai force-pushed the app-state-caching-improvements branch from ca42676 to b451ece Compare May 27, 2019 21:53
@luisivan luisivan mentioned this pull request May 27, 2019
25 tasks
// Ensure a promise is returned even if the reducer returns an array or throws
new Promise((resolve) => resolve(reducer(state, event)))
).pipe(
catchError((err) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I wasn't aware of this operator

@2color
Copy link
Contributor

2color commented May 28, 2019

956d722: Now that #305 is merged, we can use this.accounts() directly without worrying about the first emission being lost

Didn't see this and already implemented it in #297

To be on the safe side, opted to re-throw the error and end the store() stream for now, rather than silently returning the previous state and continuing the reducing

Sensible

In the future, we may want to completely move the state to be in-memory, since now we're effectively using double the storage (state and cache representations of the app's reduced state)

I agree. How do you envision the passing of state between script to app?

@sohkai
Copy link
Contributor Author

sohkai commented May 28, 2019

I agree. How do you envision the passing of state between script to app?

Good question! Been thinking a little bit about how this would work, since it'd also be required for the "triggers".

This state "trigger" could be implemented directly as a ReplaySubject(1), held in a mapping based on the app's proxy address. Any time you send a response to it, it would do a .next() on the Subject. If you request it, you get subscribed to the relevant subject (again, based on the sender's proxy address).

The ephemeral "trigger" would be exactly the same as above, but just using a normal Subject().

@sohkai sohkai merged commit 54dbdc8 into app-state-caching May 28, 2019
@sohkai sohkai deleted the app-state-caching-improvements branch May 28, 2019 17:09
2color added a commit that referenced this pull request May 31, 2019
* add handler for past events

- emit a single emission for past events
- add ability to fetch arbitrary cache keys

* Make caching happen 🌶🎲🥊

* Remove unneeded imports and add comments

* Use the share operator to prevent duplicate calls

* Remove unnecessary import

* Add accounts trigger

WIP

* Add comment about Promise.resolve

* api: update store signature to an options object and update docs

* Update test name

* Catch errors from app reducer

Fixes #262

* Add handler for external past events

* Cache external contract events

* Update docs and remove events param

* Disable store test

* Remove unneeded import

* Add initializationBlock option for external contracts

* Consistent spelling

As much as it's counter intuitive for me to use z consistency is what
matterz

* tests: improve core/proxy tests

* cosmetic(api): improve comments

* Update packages/aragon-api/src/index.js

Co-Authored-By: Brett Sun <[email protected]>

* Store init with cached state

* Clarify return value of reducer

* Clamp block number for local chains

In local chains this can yield an invalid negative value

* Ensure the pasteStates observable is fully hot

* Instantiate currentEvents in the block its used in

* Emit state and cache once pastEvents have finished processing
processed

* fixup! Clamp block number for local chains

* Ensure consistency between getCurrentEvents and getPastEvents

* Separate state cache from actual runtime state

* Remove unncessary import

* Emit sync events

* Use to for consistency in sync event

* Simplify event reduction to a single observable chain

* Use web3 instead of the proxy class in external handlers

* Remove unnecessary import

* Allow passing all web3 options to external pastEvents

* Change to strings so the statuses can be used in frontend

- symbols can't be serialised by postMessage

* Stop setting cache from creating new subscriptions

- use forkJoin instead of combineLatest

* Use single cache key for block and cached state

* fixup! Use single cache key for block and cached state

* Move accounts observable closer to usage

* App state caching: improvements (#313)

* App state caching: improvements++ (#317)

* api: commit initialized store state immediately to avoid showing non-cached state from previous runs

* api: fetch current blocks from block after cached height

* api: emit when cache has been committed, and commit cache operations one by one in store

* api: use throttleTime() instead of sampleTime() for throttling

* api: update docs for change to cache()

* wrapper: use pastEvents() strategy for caching

* Upgrade rxjs to avoid endWith() bug

* @aragon/api, @aragon/api-react: v2.0.0-beta.1

* @aragon/wrapper: 5.0.0-rc.8

* api-react: add prepublishOnly script

* Export single events constant and use strings

* Release @aragon/api 2.0.0-beta.2

* @aragon/wrapper: 5.0.0-rc.10

* api: only log debug messages on development environment (#320)

* @aragon/api: v2.0.0-beta.3
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.

2 participants