-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Changed urlService require() on app to boot faster #25750
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe top-level import of Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
���� Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (4)📚 Learning: 2025-05-29T07:45:35.714ZApplied to files:
📚 Learning: 2025-08-11T19:39:00.428ZApplied to files:
📚 Learning: 2025-10-30T17:13:26.190ZApplied to files:
📚 Learning: 2025-10-09T08:10:18.956ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
ghost/core/core/app.js(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: Legacy tests (Node 22.18.0, sqlite3)
- GitHub Check: Acceptance tests (Node 22.18.0, sqlite3)
- GitHub Check: Acceptance tests (Node 22.18.0, mysql8)
- GitHub Check: Legacy tests (Node 22.18.0, mysql8)
- GitHub Check: Ghost-CLI tests
- GitHub Check: Lint
- GitHub Check: Unit tests (Node 22.18.0)
- GitHub Check: Build & Push Docker Image
ghost/core/core/app.js
Outdated
| const urlService = require('./server/services/url'); | ||
| if (req.app.get('maintenance') || config.get('maintenance').enabled || !urlService.hasFinished()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for urlService references in the codebase
echo "=== Searching for urlService imports and usage ==="
rg -n --type=js 'require.*url.*service|urlService' -g '!node_modules' -C 3
echo ""
echo "=== Searching for hasFinished and related methods ==="
rg -n --type=js 'hasFinished|isFinished|ready.*url|\.finished' -g '!node_modules' -C 2
echo ""
echo "=== Looking for initialization patterns at boot ==="
rg -n --type=js 'require.*services|init|boot' -g '!node_modules' | head -50Repository: TryGhost/Ghost
Length of output: 50371
🏁 Script executed:
#!/bin/bash
# Get app.js context around lines 10-11
echo "=== app.js context (lines 1-30) ==="
head -30 ghost/core/core/app.js | cat -n
echo ""
echo "=== Check if there's any documentation or changes related to this ==="
rg -n 'maintenance.*urlService|urlService.*maintenance' -g '!node_modules' -C 2Repository: TryGhost/Ghost
Length of output: 1718
Deferred urlService initialization will cause initial requests to return 503 Maintenance Mode.
The require() is now deferred to first request execution (line 10), meaning urlService is required inside the per-request middleware. When the first request arrives, isMaintenanceModeEnabled() will require urlService and immediately check hasFinished(). Since initialization has not yet started or completed, this check will return true, causing the middleware to respond with 503 and serve maintenance.html. This blocks legitimate traffic until urlService finishes initializing on a subsequent request.
Initialization should not be deferred to request handling. Keep the require() at module load time so urlService begins initializing during boot, and hasFinished() will be true by the time the first request arrives.
🤖 Prompt for AI Agents
In ghost/core/core/app.js around lines 10-11, the urlService is required inside
the per-request check which defers initialization and causes the first request
to see hasFinished() === false and return 503; move the const urlService =
require('./server/services/url'); out of the request handler to module load/top
of the file so urlService begins initializing during boot and hasFinished() will
be true by first request, leaving the rest of the middleware logic unchanged.
1e82669 to
cceb482
Compare
ref https://linear.app/ghost/issue/BER-3132 - The urlService `require()` adds 70-100ms on boot time, this is due to the package's own initialization. Since it's not needed at boot, it can be moved inside the isMaintenanceModeEnabled function.
cceb482 to
accdd96
Compare
ref https://linear.app/ghost/issue/BER-3132
require()adds 70-100ms on boot time, this is due to the package's own initialization. Since it's not needed at boot, it can be moved inside the isMaintenanceModeEnabled function.