Skip to content

Query with globals and complex blocks significantly slower than a collection with the same blocks using postgreSQL #10589

Open
@Robbe95

Description

@Robbe95

Describe the Bug

When creating a lot of blocks and using them in a GlobalConfig with postgreSQL, the query gets really slow.
Using those same blocks in a collections stays fast.
Here is an example using the global, it takes more than 1 second on average. This number grows the more blocks are added, in my project where i noticed this it is up to 2.5 seconds.

Image

Using the exact same setup, but within a collection, suddenly the API call only takes 50ms on average.

Image

The setup for the global and collection are basically exactly the same, for more details look in the reproduction repo

Image Image

I don't think I am doing anything wrong, but I am not that familiar with PayloadCMS as it is my first project in it.

Link to the code that reproduces this issue

https://github.com/Robbe95/payload-slow-global

Reproduction Steps

  1. Setup local postgreSQL server
  2. Setup .env with DATABASE_URI and PAYLOAD_SECRET
  3. Run the server
  4. Add a complex blocks structure, see https://github.com/Robbe95/payload-slow-global/blob/main/src/blocks/testBlocks.ts
  5. Make a pages collection and add the blocks structure
  6. Make a global collection and add the blocks structure
  7. Run the API call http://localhost:3000/api/pages/1
  8. Run the API call http://localhost:3000/api/globals/home-page
  9. Notice the speed difference

Which area(s) are affected? (Select all that apply)

db-postgres

Environment Info

Binaries:
  Node: 22.6.0
  npm: 10.8.2
  Yarn: N/A
  pnpm: 9.15.4
Relevant Packages:
  payload: 3.17.1
  next: 15.1.0
  @payloadcms/db-postgres: 3.17.1
  @payloadcms/email-nodemailer: 3.17.1
  @payloadcms/graphql: 3.17.1
  @payloadcms/next/utilities: 3.17.1
  @payloadcms/payload-cloud: 3.17.1
  @payloadcms/richtext-lexical: 3.17.1
  @payloadcms/translations: 3.17.1
  @payloadcms/ui/shared: 3.17.1
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.0.0: Mon Aug 12 20:52:12 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 10

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions