Fix Knex transaction errors in prod#162
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce production DB/Knex issues (transaction/connection pool pressure) by adjusting SQLite connection behavior, optimizing “hot path” queries, and adding a functional concurrency regression test.
Changes:
- Adjust SQLite pool/connection initialization (WAL, synchronous mode, busy timeout) and force a single shared SQLite connection.
- Add indexes on frequently queried columns in
services,workspaces, andtokens. - Refactor several endpoints to query
Service/Workspace/Tokendirectly (instead of relation queries) and add a concurrency-focused functional test for/user/data.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/functional/dashboard/data.spec.ts | Adds a functional test that performs concurrent /user/data requests to catch pool/connection exhaustion regressions. |
| database/migrations/1774667000000_add_database_hot_path_indexes.ts | Adds indexes intended to speed up common lookups and reduce DB load. |
| config/database.ts | Updates SQLite pool sizing and connection PRAGMAs to improve concurrency characteristics and reduce lock contention. |
| app/Models/User.ts | Refactors token lookup/creation to use Token.query() / Token.create() directly. |
| app/Controllers/Http/WorkspaceController.ts | Refactors workspace UUID check and workspace ordering computation (count query), plus orders workspace listing output. |
| app/Controllers/Http/ServiceController.ts | Introduces a shared “load user services” query and minor response shaping refactor. |
| app/Controllers/Http/Dashboard/ExportController.ts | Switches to direct Service/Workspace queries with stable ordering for exports. |
| app/Controllers/Http/Dashboard/DataController.ts | Switches to direct Service/Workspace queries with stable ordering and explicit empty arrays when unauthenticated. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit tries to fix the spam on knex transaction errors not being closed which might be overloading the server CPU. Not sure if this works as it is kind of difficult to test it.