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

[API Design](Cache): Should ignore passed params into query for generating cache key if not expected by query #349

Open
NazariiShvets opened this issue Sep 2, 2023 · 2 comments
Labels

Comments

@NazariiShvets
Copy link
Contributor

NazariiShvets commented Sep 2, 2023

Precondition: docs

So, the key is a hash of the following data:
- SID of the Query
- params of the particular call of the Query
- current values of all external Stores that affect Query
To get short and unique key, we stringify all data, concatenate it and then hash it with SHA-1.

This design desigion does not take into account pattern within effector community with sample:
If EventPayload of target is void, user can pass data in any shape without any warning, thus it can be unintuitive, why they hit cache miss on, for example, page route params refetch

const getDataQuery = createQuery({
  effect: () => Promise.resolve([])
})

sample({
   clock: pageOpened // Event<{ params: { id: '1' }, query: {} }>
   target: getDataQuery.start
})

sample({
   clock: pageUpdated // Event<{ params: { id: '2'}, query: {} }>
   target: getDataQuery.start
})

@igorkamyshev igorkamyshev added type:bug Something isn't working scope:core labels Sep 4, 2023
@igorkamyshev
Copy link
Owner

It works for createJsonQuery, so I think we should back port this feature to creteQuery as well.

@igorkamyshev
Copy link
Owner

So, it's more complicated 🤔

What if we replace the handler of a Query during fork?

const q = createQuery({
  effect: () => Promise.resolve([])
})

const scope = fork({
  handlers:[[q.__.executeFx, (p) => return [p]]]
})

We cannot skip params in this case, it would be harmful. So, we have to check usage of params in runtime.

I suggest you just remove params in sample by fn. Something like this 👇

const getDataQuery = createQuery({
  effect: () => Promise.resolve([])
})

sample({
   clock: pageOpened // Event<{ params: { id: '1' }, query: {} }>
   fn: () => null,
   target: getDataQuery.start
})

sample({
   clock: pageUpdated // Event<{ params: { id: '2'}, query: {} }>
   fn: () => null,
   target: getDataQuery.start
})

We will think about improving DX in this case later 🙏

@igorkamyshev igorkamyshev added type:enhancement New feature or request discussion and removed type:bug Something isn't working labels Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants