fl-query icon indicating copy to clipboard operation
fl-query copied to clipboard

QueryClient.invalidateQueries([...])

Open PetrKubes97 opened this issue 1 year ago • 6 comments

For my project, this would be more useful than refetchQueries, as I don't want to be loading too much stuff in the background.

PetrKubes97 avatar Mar 06 '24 13:03 PetrKubes97

I think what you want to achieve is invalidateQueries? You want to just make them stale but don't want the queries to refresh immediately and only refresh when required?

KRTirtho avatar Mar 08 '24 11:03 KRTirtho

Yes, exactly

PetrKubes97 avatar Mar 08 '24 12:03 PetrKubes97

I've solved it with an extension. Let me know if it makes sense to you to include in the library. @KRTirtho

extension FLQueryClient on QueryClient {
  void invalidateWithPrefix(String prefix) {
    final queries = getQueriesWithPrefix(prefix);
    for (var query in queries) {
      query.reset();
      if (query.hasListeners) {
        query.refresh();
      }
    }
  }
}

PetrKubes97 avatar Mar 17 '24 21:03 PetrKubes97

Yeah actually it was planned already. But never made it in a release.

But what you're suggesting, has query.refresh so it doesn't actually make any difference that refreshWithPrefix

KRTirtho avatar Mar 19 '24 14:03 KRTirtho

Are you sure it does not make any difference?

I've had a lot of queries and calling refreshWithPrefix had refreshed even the inactive ones, resulting in 429 errors and unnecessary server load.

My implementation seems to correctly mark the queries for reload only after user visits their page.

PetrKubes97 avatar Mar 19 '24 14:03 PetrKubes97

Ok, so I guess because of the hasListeners it'll update the UI only when it's mounted otherwise it'll be resetted.

We can add it ✅

KRTirtho avatar Mar 19 '24 16:03 KRTirtho