fix(drizzle): correctly apply query limit on polymorphic joins#15652
fix(drizzle): correctly apply query limit on polymorphic joins#15652JessRynkar wants to merge 1 commit intomainfrom
Conversation
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
048a184 to
af42b76
Compare
|
|
||
| let limitOffsetSQL = sql.empty() | ||
| if (limit) { | ||
| limitOffsetSQL = sql.raw(` LIMIT ${limit}`) |
There was a problem hiding this comment.
I didn't think we are doing sql.raw anymore.
There was a problem hiding this comment.
Ah shoot, I am not as familiar with the Postgres workings. I'll take another look
There was a problem hiding this comment.
I updated this line to not use sql.raw ^
I kept it for identifiers (table/column names) since that matches the existing pattern (I see ~20 usages in traverseFields.ts, parseParams.ts, json.ts, etc) These are all internally-generated names, not user input, so maybe that is the difference?
If we're trying move away from sql.raw entirely, what's the preferred approach?
af42b76 to
803a497
Compare
What?
Fixes an issue where querying folders with nested subfolders returned incorrect results when using SQL databases.
Why?
When resolving nested folder relationships, the generated polymorphic
UNIONquery appliedLIMITat the global level. This caused the limit to be enforced across the entire result set before rows were correlated back to their respective parent folders.As a result, some parents received incomplete or incorrect child data.
How?
The polymorphic join query has been restructured so that parent correlation occurs before applying the
LIMIT. This ensures:LIMITis enforced per parentTesting
folders > int