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

Invalidating long running initial GET requests. #2215

Closed
mjwvb opened this issue Apr 7, 2022 · 2 comments
Closed

Invalidating long running initial GET requests. #2215

mjwvb opened this issue Apr 7, 2022 · 2 comments

Comments

@mjwvb
Copy link

mjwvb commented Apr 7, 2022

We have a slight issue with invalidating initial running requests using tags. Some of our GET requests take a couple of seconds to finish, some even 10 seconds (yeah, it is what it is). During the fetching process the user is allowed to do mutations on the same underlying table, causing tags for that table to be invalidated. However, no tags are provided yet as they are provided only after the GET request is finished. So there's no way for us to invalidate that initial long request while still running.

It would help if we can pre-provide certain tags to our endpoint, which we can use to invalidate requests that are not fully loaded yet. But as far as I can see, there's no such thing. We have a couple of workarounds in mind, like invalidating endpoints by providing an extra data version number in the endpoint argument. Before we go the workaround route, are there any tips to handle this situation?

Thanks, and thanks for the amazing library (RTK + query). Works great!

@phryneas
Copy link
Member

phryneas commented Apr 8, 2022

That would probably not help you.
invalidateTags starts new queries for all impacted queries, you are right on that.

But in RTK-Q, if a query is already running, a new query won't be started. So even if you would invalidate that, it would not cause a new request while the old one was already running.
Without really knowing our application I'm also out of ideas on a good solution for you there, I'm sorry.

@mjwvb
Copy link
Author

mjwvb commented Apr 8, 2022

So invalidation doesn't work for running queries at all. That's something I didn't expect, but was on my list to check later on. It's essential that it works for us, although long running queries are rare. So I'm looking for workarounds here.

Just out of my head, isn't it something we can fix by first aborting all the affected running queries, and then invalidate? Like so:

const tags = ['Post']
const invalidatedBy = selectInvalidatedBy(getState(), tags);

// Find and abort the operation promise for each query corresponding to given tags
invalidatedBy.forEach(({ endpointName, originalArgs }) => {
    const operationPromise = api.util.getRunningOperationPromise(endpointName, originalArgs)
    operationPromise.abort()
})

dispatch(api.util.invalidateTags(tags))

Still not a fix for the initial running queries though

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

No branches or pull requests

3 participants