payloadcms / payloadcms/payload

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

Open
#10,589 6 comments 0 reactions 1 assignee View on GitHub

@r1tsuu is already working on this.

Since Jan 16, 2025.

status: cant-reproduce
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.