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

fix resetStore running stopped queries #960

Merged
merged 6 commits into from
Dec 12, 2016

Conversation

machard
Copy link
Contributor

@machard machard commented Nov 25, 2016

Hi,

there is an issue actually when stoping a query and then resetting the store.
the query will actually be refetched.

It seems to be a possible logical fix. but it fails tests

@apollo-cla
Copy link

@machard: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

Copy link

@yurigenin yurigenin left a comment

Choose a reason for hiding this comment

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

This will have a side effect of breaking logic of calling updateQueries on a mutation for this deleted observable query.

@machard
Copy link
Contributor Author

machard commented Nov 25, 2016

Ok, so what about updating ObservableQuery.refetch method to return early if the ObservableQuery has no subscribers ?

I also don't understand why we do a refetch (forceFetch https://github.com/apollostack/apollo-client/blob/master/src/core/ObservableQuery.ts#L163) on resetStore as calling resetStore means "empty the store" as i understand it. A possible other solution would be to do a noFetch refresh of the observable queries when resetting the store ?

@machard
Copy link
Contributor Author

machard commented Nov 27, 2016

ok after reading http://dev.apollodata.com/react/auth.html#login-logout, i see that it's intentional to reset the store as it is on the server so none of the 2 methods in the previous comment could be a match.
But it does seem like a real problem that teardowned queries are refetch on reset store.

@tmeasday
Copy link
Contributor

I think it is pretty reasonable to not refetch the query if it has been torn down on resetting store. @helfer what do you think?

@helfer
Copy link
Contributor

helfer commented Nov 28, 2016

@tmeasday Yes, the query definitely shouldn't be refetched if it has been stopped.

@machard I think the proper fix for now would be to only refetch non-stopped queries here.

@machard
Copy link
Contributor Author

machard commented Nov 29, 2016

is there already a way to know for sure if a request has been toredown (observers.length == 0 ?) or should i add a toredown property to the observableQuery ?

@machard
Copy link
Contributor Author

machard commented Dec 1, 2016

@helfer ?

@helfer
Copy link
Contributor

helfer commented Dec 1, 2016

@machard I'm not sure what you mean. A query isn't started until it has listeners, and when it has no more listeners, it is stopped. What I proposed was checking the stopped property in the store before refetching.

@Siyfion Siyfion mentioned this pull request Dec 5, 2016
@machard machard force-pushed the machard-fix-stopQuery branch from 6b378cd to 950c7d9 Compare December 5, 2016 12:34
@machard
Copy link
Contributor Author

machard commented Dec 5, 2016

@helfer yes you answered my question. I updated the PR, is that what you expected ?

@helfer
Copy link
Contributor

helfer commented Dec 8, 2016

@machard yes, thanks a lot, that's exactly what I meant! It would be awesome if you could add a test for this as well that makes sure stopped queries are really not refetched. Do you think you could do that? Basically it should start a query, then stop it, then call refetch store and make sure no network request is sent. To make sure the test actually works, you could try and see if the test fails when you remove your changes, and passes when you add them back in.

Let me know if you can do it!?

paulshen added a commit to lugg/apollo-client that referenced this pull request Dec 9, 2016
@machard
Copy link
Contributor Author

machard commented Dec 12, 2016

@helfer done!

@helfer
Copy link
Contributor

helfer commented Dec 12, 2016

Thanks a lot, it looks great! 🙂

I'm going to merge it now, and then make the timeout a bit shorter because nobody wants to wait 400 ms for a test to finish 😉

@helfer helfer merged commit da4a24c into apollographql:master Dec 12, 2016
@helfer
Copy link
Contributor

helfer commented Dec 12, 2016

And I guess I'll update the changelog. I didn't even notice that you deleted the todo list that comes with the PR template. That's not what it's for 😄

@machard
Copy link
Contributor Author

machard commented Dec 12, 2016

cool !
for the timeout, I took the one i saw on other tests :/ https://github.com/apollostack/apollo-client/blob/master/test/QueryManager.ts#L2234 for example

@helfer
Copy link
Contributor

helfer commented Dec 13, 2016

@machard Oh, right. I should probably go and reduce those where possible to make tests run faster.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants