-
Notifications
You must be signed in to change notification settings - Fork 28
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
Single call to notification.useData
results in 100+ queries to the database
#27
Comments
Just saw this. Former Cord engineer here with a few thoughts. Yeah, this sort of issue is one that Cord ran into from time to time. We'd typically fix it as problems presented themselves -- and since we were running on a pretty beefy AWS RDS instance which could take a lot of abuse before things got bad, and GraphQL, when naively used, causes issues like this (and the actual API that the Cord server speaks is largely GraphQL) -- each notif has an application field (or has an author field who has an application field or something like that) and so you load the same app O(n) times. GraphQL has a standard solution to this, which is dataloader, which Cord uses. These dataloaders coalesce queries together so that the O(n) requests for data become a single DB query, with the results split back up to the calling code. This... mostly works, with a few problems that Cord consistently ran into:
Hopefully that is useful context on where to start looking at this. My guess would be the problem is (1), we're just not dataloader'ing something somewhere that we should be. But, it could be the more esoteric (3). And I mention (2) as background here, in case you see it. |
We had a development environment with a hosted database, and we noticed how we somehow ploughed throught 1.5gb of egress per day per single developer only for this Cord instance.
Mind you, this database has not much data at all, mostly short testing messages:
Seems like a single call to
notification.useData
from the frontend results in ~100 queries (30 queries of threads, even though the number of total threads is less) to the database, only to return 10 notifications back. On every single page load.Now, I wonder if anyone else has witnessed this, or have we misconfigured something and missing some caching or anything else?
A single page load with an empty cord context (completely empty page, no re-renderings or anything), results in 7 queries of the below to the database:
The text was updated successfully, but these errors were encountered: