-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Framework: Add sync-handler wrapper #2843
Conversation
7443c06
to
6f2eb76
Compare
const oauthToken = require( 'lib/oauth-token' ), | ||
requestHandler = require( 'lib/wpcom-xhr-wrapper' ); | ||
const oauthToken = require( 'lib/oauth-token' ); | ||
const requestHandler = config.isEnabled( 'sync-handler' ) |
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.
I would be for splitting it into if {} else
We have 4 different permutations here, so I would do
if( config.isEnabled( 'sync-handler' ) ) {
const req... = ...
} else {
const....
}
and move it to line 16, then we dont have to duplicate the code in line 19 & 25
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.
The thing here is you also need to decide what request handler will be wrapped by sync-handler. It's a double nested condition. And the wpcom instantiation is different accordingly.
if ( config.isEnabled( 'oauth' ) ) {
// ...
if( config.isEnabled( 'sync-handler' ) ) {
const req... = ...
} else {
const....
}
} else {
// ...
if( config.isEnabled( 'sync-handler' ) ) {
const req... = ...
} else {
const....
}
}
I can add a const
to get the config key to avoid call the config() function twice.
65a97f9
to
57a7b96
Compare
const oauthToken = require( 'lib/oauth-token' ), | ||
requestHandler = require( 'lib/wpcom-xhr-wrapper' ); | ||
const oauthToken = require( 'lib/oauth-token' ); | ||
const requestHandler = addSyncHandlerWrapper |
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 ternary seems to be duplicated in line 20 and 26 :)
Move it to 17 maybe?
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.
It isn't duplication: the requires are different.
Not sure if it's correct, though. The first block has lib/wpcom-xhr-wrapper
both times. The second block has wpcom-proxy-request
and then lib/wpcom-xhr-wrapper
.
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.
yup. you're right.
I've given this a quick test with /menus. Client menu data is updated with responses from POST requests, so everything works fine unless the page is refreshed, when an initial population is performed from stale GET data, meaning any previous modifications are not visible. Maybe we should add a blacklist facility to allow us to indicate that certain API endpoints should never be cached? |
Yes, in fact we did it in our first approach. a143572 And on the other hand we're trying to improve the performance when the local data must be updated and at the same time find a way to notify to client( calypso) of these changes. |
@retrofox I think the double-callback branch should be merged into this PR. The stale data issue is likely enough of a blocker that this PR should not be merged without it, even in development. The odd behavior with stale data is otherwise likely to confuse developers as they are working on their features. We should also add a blacklist mechanism if/when we find an endpoint for which the double-callback approach runs into problems. |
ok @rralian |
1337f3f
to
8d2b642
Compare
@retrofox you may want to rebase with master to work around build breakages. |
thanks @gwwar |
8d2b642
to
d40e279
Compare
I really would like try to do it on this PR. |
bee8fd9
to
33069b8
Compare
Hmm, additive properties that we expect could be a mess. Since this is a generic low level cache, I'm not sure if we could target all the endpoints. Probably ~1d max age might make more sense. |
Ha! After a fair bit of debugging I figured out the issue was not quite what it seemed. The dirty cache to clear the post-list and the second callback where all working as expected. The issue is that |
5e1869e
to
4206d49
Compare
@retrofox I would prefer that we not add the reader endpoint until/unless we can confirm it doesn't have the same corner case issues we found for the post-list. Let's just keep this one simple, we can add the reader endpoints separately. |
👍 |
4206d49
to
7ad16b6
Compare
This is working well for me, though it looks like this needs to be rebased again. There are still some issues we need to figure out, but I think we can merge this now, especially considering this is limited to development. 👍 |
previously we were skipping the second callback from the sync-handler because setDefaultMenu() inside menu-data.js did not gracefully handle a double-callback. I've updated it to more gracefully handle the double-callback, so the sync-handler works as expected for this case as well.
because the receivePage method gets run for both pagination queries as well as sync-queries, we can no longer assume that all new posts can go at the end of the list. So we need to sort posts after we receive them.
7ad16b6
to
0aacbb8
Compare
rebased. waiting for circle cli as well. |
Framework: Add sync-handler wrapper
This adds a wrapper to sync the data gotten from the REST-API GET responses.
The idea with this data storing is allow provide data when the user is offline.
This wrapper works like a middleware that intercepts every GET request from the user and does, in short, three actions:
This approach is not ready to production. This feature is allowed through of its
sync-handler
config key.