Improved performance of post previews#22554
Conversation
WalkthroughA new migration file has been created to add an index to the Suggested labels
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
It looks like this PR contains a migration 👀 General requirements
Schema changes
Data changes
|
ref https://linear.app/ghost/issue/ENG-2081 - Added an index to the `posts` table on the `uuid` column to prevent a whole table scan when doing a posts preview which use a posts UUID to match against - On sites with a large number of posts this can currently cause lookups to take several seconds just to look up a single post Cost before index: | -> Limit: 1 row(s) (cost=68964 rows=1) (actual time=333..333 rows=1 loops=1) -> Filter: (posts.uuid = '5e75e7da-bdcc-4a5c-ac7f-876041f4aa1d') (cost=68964 rows=8127) (actual time=333..333 rows=1 loops=1) -> Table scan on posts (cost=68964 rows=81271) (actual time=0.0641..325 rows=78701 loops=1) Cost after index: | -> Limit: 1 row(s) (cost=0.63 rows=1) (actual time=0.0717..0.0718 rows=1 loops=1) -> Index lookup on posts using posts_uuid_test_index (uuid='5e75e7da-bdcc-4a5c-ac7f-876041f4aa1d') (cost=0.63 rows=1) (actual time=0.0707..0.0707 rows=1 loops=1)
43f0d29 to
5d385ba
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
ghost/core/core/server/data/schema/schema.js (1)
53-53: Excellent performance optimization by adding index to posts.uuidAdding an index to the UUID column is a well-considered optimization that will significantly improve query performance when looking up posts by UUID. According to the PR description, this change reduced lookup costs from 68964 rows to 0.63 rows and decreased lookup time from ~333ms to ~0.0718ms.
This change directly addresses the performance issues with post previews on sites with large post collections, where lookups were previously taking several seconds due to full table scans.
Consider reviewing other frequently queried columns in the system for potential indexing opportunities, especially for tables that grow large over time.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between ce75740869af204000e5a55cd59a515e0026c81d and 5d385ba.
📒 Files selected for processing (3)
ghost/core/core/server/data/migrations/versions/5.114/2025-03-19-03-13-04-add-index-to-posts-uuid.js(1 hunks)ghost/core/core/server/data/schema/schema.js(1 hunks)ghost/core/test/unit/server/data/schema/integrity.test.js(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- ghost/core/core/server/data/migrations/versions/5.114/2025-03-19-03-13-04-add-index-to-posts-uuid.js
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: Ghost-CLI tests
- GitHub Check: Database tests (Node 20.11.1, sqlite3)
- GitHub Check: Database tests (Node 22.13.1, mysql8)
- GitHub Check: Regression tests (Node 20.11.1, mysql8)
- GitHub Check: Database tests (Node 20.11.1, mysql8)
- GitHub Check: Database tests (Node 18.12.1, mysql8)
- GitHub Check: Unit tests (Node 20.11.1)
- GitHub Check: Unit tests (Node 18.12.1)
🔇 Additional comments (1)
ghost/core/test/unit/server/data/schema/integrity.test.js (1)
38-38: Schema hash updated to reflect database changesThis update to the hash value is required due to the addition of an index to the 'uuid' column in the 'posts' table. The hash value ensures that any changes to the database schema are properly tracked and validated.
ref https://linear.app/ghost/issue/ENG-2081
poststable on theuuidcolumn to prevent a whole table scan when doing a posts preview which use a posts UUID to match againstCost before index:
Cost after index:
Adding the index on a site with 140k+ posts took ~1.4 seconds: