prisma / studio

🎙️ The easiest way to explore and manipulate your data in all of your Prisma projects.
https://www.prisma.io/studio
1.86k stars 47 forks source link

Prisma Studio handles models with n:m relations in a way that makes it unusable for larger DBs #751

Open henrikuper opened 3 years ago

henrikuper commented 3 years ago

Bug description

I use Prisma Studio in the browser as well as the Mac app.

Prisma studio throws timeouts when querying some tables or is extremely slow or freezes all the time. I guess this is because the requested data comes from a model that has n:m relations. Some of these relations have over 10000 connections. I guess Prisma studio uses the include option for all attributes. This leads to more than 10,000 connections being requested and sent. Since this leads to very large amounts of data, it results in a timeout/freeze.

For example, imagine you have a model user with the attribute Follower. A user has 10k followers. Prisma studio would then request the data of all 10k followers as soon as this user is requested.

Even if you unselect certain attributes in Prisma studio, they are still requested.

How to reproduce

  1. create a model User with the n:m relation follower
  2. create 100k user and connect them with each other
  3. open Prisma Studio and open the model user

Maybe not on local host but definitely on dev/prod server the query will timeout or take forever.

Expected behavior

There is more than one option:

Maybe you have some more or better ideas.

Prisma information

Just use a schema with large n:m relations

Environment & setup

Prisma Version

prisma 2.27.0

sdnts commented 3 years ago

Hey @henrikuper yeah your assessment is 100% correct:

Right now, Studio does a include for all relations of a model when you open the model. All it needs is the number of relation connections to display the count, so I can aggregate this separately. That should help significantly.

henrikuper commented 3 years ago

Hi @madebysid Thanks for pointing that out. I know that the include is currently also used to click on the connections to manually add / remove connections. But it would safe a lot of time, if this would happen in a second query as soon as it is needed (most of the time it is not needed).

tobiaghiraldini commented 3 years ago

Hey there! I just upgraded prisma to the 2.29 version, as I was facing this issue on a large db with many relations. This issue has been added to the 2.29 milestone, but prisma studio still behave in the same way it did before, performing an include of all the related model in the first query, making prisma studio to collapse as soon as I try to view some data.

Which is the milestone to expect this fix in? thank you!

henrikuper commented 3 years ago

@madebysid any update here? Still having the issue. I really cant work with studio right now. It takes up to 1 min to load the lists...

It would already help if you would allow to only load 10 or 5 objects instead of 100 as a default. This would not solve the issue, but it would decrease the time by 90% Which would be ok for the time until there is a real fix/improvement.

sdnts commented 3 years ago

I'm looking into a bunch of Studio issues this week, and this is pretty high on that list. I will try my best to make sure this gets shipped with the next stable version of Prisma (scheduled for next Tuesday), but I should be able to ship a dev version before that with the fix. I will let you know when that happens.

Thanks for being patient!

henrikuper commented 2 years ago

@madebysid Have you had the time to look at the problem? The bigger the database gets, the worse the problem gets... meanwhile I can't look at more than half of the tables, because they all don't load within several minutes...

I now have to build a script for everything I want to read/write. This really can't be the solution.

NicolajKN commented 2 years ago

I'm having this issue as well with relations with hundreds of thousands of records. My suggestion would be some kind of flag that turns off the row count, if it is otherwise not possible to optimize this further.

neoromantic commented 2 years ago

For me, the problem starts much earlier - I have just hundreds of records.

I have a User model and 7 other models that links to it.

Prisma Studio fails to load User list when I have just hundreds of records in tables.

salcedosalad commented 5 months ago

Any updates on this one?