Optimize: Wrap custom field creation in transaction#145
Merged
ManukMinasyan merged 2 commits intorelaticle:mainfrom Feb 21, 2026
Merged
Conversation
Fixes Sentry issues RELATICLE-CRM-2Z, RELATICLE-CRM-30, RELATICLE-CRM-31 Wraps the ~20 custom field creation calls in a single DB transaction to reduce overhead during team creation. Impact: - Reduces transaction overhead - Improves performance during registration/OAuth - Still creates all fields atomically Closes #142
There was a problem hiding this comment.
Pull request overview
This PR optimizes team creation performance by wrapping custom field creation in a single database transaction. The change addresses Sentry issues related to N+1 queries and transaction overhead during team registration and OAuth flows.
Changes:
- Wraps the custom field creation loop in a
DB::transaction()to reduce overhead from ~20 individual transactions to 1 single transaction - Adds an inline comment explaining the optimization purpose
- Maintains atomicity by ensuring all custom fields are created or none are (all-or-nothing behavior)
Contributor
ManukMinasyan
left a comment
There was a problem hiding this comment.
Two small fixes needed:
-
Unused variable capture —
$teamin theuseclause is not referenced inside the closure. Changefunction () use ($team): voidtofunction (): void. -
Unnecessary comment — The
// Wrap custom field creation in transaction to reduce overheadcomment restates whatDB::transaction()already communicates. Remove it.
- // Wrap custom field creation in transaction to reduce overhead
- DB::transaction(function () use ($team): void {
+ DB::transaction(function (): void {Otherwise LGTM — clean, focused change.
- Remove unused $team from closure - Remove redundant comment
Contributor
|
Heey, @NeloNew is this PR ready for merge? |
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.
Fixes Sentry Issues
Resolves #142
Problem
During team creation, ~20 custom fields are created in a loop. Each call to
$migrator->create()runs in its own transaction, adding overhead.Solution
Wrap all custom field creation calls in a single DB transaction to reduce overhead.
Changes
Impact
Testing
Notes
This is a performance optimization that doesn't change functionality. For further optimization, the
relaticle/custom-fieldspackage could add a batch create method to eliminate the EXISTS checks entirely.