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

Hooks extension improvement proposal #2

Open
MaxBolotnyi opened this issue Apr 30, 2024 · 3 comments
Open

Hooks extension improvement proposal #2

MaxBolotnyi opened this issue Apr 30, 2024 · 3 comments

Comments

@MaxBolotnyi
Copy link

Hi,
First of all, thank you for all the effort with that project. The idea of bringing prisma to react-native and expo is breathtaking and promising.

The current implementation of the react hooks extension makes a query to a database on a per-hook basis, which could lead to a redundant query waterfall in a scenario where the same hook/query is utilized in multiple components at the same time. Would you consider implementing the shared cache for the same queries 'batching' the same calls into a single one sharing a common RAM cache over all the hooks that read that same query?
The TanStack Query uses a similar approach for batching and sharing the cache over its query hooks.

Also, would you be open to accepting the PR for that implementation to help you?

@MaxBolotnyi MaxBolotnyi changed the title Hooks extention imrovement proposal Hooks extension improvement proposal Apr 30, 2024
@sorenbs
Copy link
Member

sorenbs commented Apr 30, 2024

Hey Max - thank you for your interest!

What you describe is exactly what we have planned. Our goal for the first release is to get an API that we feel good about in the hands of developers, such that we can gather feedback and lock-down a final API. For example, it is convention that hooks be free functions ala useQuery() rather than properties on an object ala prisma.user.findFirst() - is that a real concern that we should address by changing the API, or is the commonality with the normal Prisma API enough of a benefit to break this convention? That's the kinds of questions we seek to get answered by the end of Q2.

Following that, we want to focus on optimizations. a shared cache as you propose is an important optimization. Another one is reducing the size of the React Native library. It's currently 25 mb, which is fine for gathering initial feedback, but not really acceptable for broader use in production apps.

We generally welcome contributions, and would love to see a pr for the shared cache implementation. We would need extensive test coverage before merging it, and we can collaborate on that aspect if you like. The current code base is not well tested, so we'll need to improve here before we introduce additional complexity.

@MaxBolotnyi
Copy link
Author

Hi Soren, thank for the valuable reply!

I would be glad to collaborate and roll out the PR fot the proposed cache implementation. Could you please point me out to any documentation regarding the flow that would fit you best, or would it be best just to roll out the draft version of it and start from there?

P.S. Regarding the question you raised in the first paragraph, I would personally put my vote on the object property implementation and keep it aligned with the usual Prisma API, but that's just my humble opinion, though

@sorenbs
Copy link
Member

sorenbs commented May 25, 2024

P.S. Regarding the question you raised in the first paragraph, I would personally put my vote on the object property implementation and keep it aligned with the usual Prisma API, but that's just my humble opinion, though

Thank you for that feedback!

If you simply fork the repo and prepare a pull request, then we can take it from there. Let me know if you need any help. You are welcome to ping me on Twitter if I am slow to reply here :-)

Also, I just announced this at app.js in Krakow. You can find the blogpost here: https://www.prisma.io/blog/bringing-prisma-orm-to-react-native-and-expo

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

2 participants