-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
perf(releases): Batch CommitAuthor queries in set_commits #106318
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -612,6 +612,84 @@ def test_long_email(self) -> None: | |
| assert commit.author is not None | ||
| assert commit.author.email == truncatechars(commit_email, 75) | ||
|
|
||
| @receivers_raise_on_send() | ||
| def test_multiple_authors(self) -> None: | ||
| """Test that multiple unique authors are created and existing authors are reused.""" | ||
| org = self.create_organization(owner=Factories.create_user()) | ||
| project = self.create_project(organization=org, name="foo") | ||
| repo = Repository.objects.create(organization_id=org.id, name="test/repo") | ||
|
|
||
| # Pre-create one author to test reuse | ||
| existing_author = CommitAuthor.objects.create( | ||
| organization_id=org.id, | ||
| email="[email protected]", | ||
| name="Old Name", | ||
| ) | ||
|
|
||
| release = Release.objects.create(version="abcdabc", organization=org) | ||
| release.add_project(project) | ||
| release.set_commits( | ||
| [ | ||
| { | ||
| "id": "a" * 40, | ||
| "repository": repo.name, | ||
| "author_email": "[email protected]", | ||
| "author_name": "Author One", | ||
| "message": "commit 1", | ||
| }, | ||
| { | ||
| "id": "b" * 40, | ||
| "repository": repo.name, | ||
| "author_email": "[email protected]", | ||
| "author_name": "Author Two", | ||
| "message": "commit 2", | ||
| }, | ||
| { | ||
| "id": "c" * 40, | ||
| "repository": repo.name, | ||
| "author_email": "[email protected]", # Test case-insensitive reuse | ||
| "author_name": "New Name", # Test name update | ||
| "message": "commit 3", | ||
| }, | ||
| { | ||
| "id": "d" * 40, | ||
| "repository": repo.name, | ||
| # No author_email - should handle gracefully | ||
| "message": "commit 4", | ||
| }, | ||
| ] | ||
| ) | ||
|
|
||
| # Verify new authors were created | ||
| assert CommitAuthor.objects.filter( | ||
| organization_id=org.id, email="[email protected]" | ||
| ).exists() | ||
| assert CommitAuthor.objects.filter( | ||
| organization_id=org.id, email="[email protected]" | ||
| ).exists() | ||
|
|
||
| # Verify existing author was reused (not duplicated) and name was updated | ||
| assert ( | ||
| CommitAuthor.objects.filter( | ||
| organization_id=org.id, email="[email protected]" | ||
| ).count() | ||
| == 1 | ||
| ) | ||
| existing_author.refresh_from_db() | ||
| assert existing_author.name == "New Name" | ||
|
|
||
| # Verify commits have correct authors | ||
| commit_a = Commit.objects.get(repository_id=repo.id, key="a" * 40) | ||
| assert commit_a.author is not None | ||
| assert commit_a.author.email == "[email protected]" | ||
|
|
||
| commit_c = Commit.objects.get(repository_id=repo.id, key="c" * 40) | ||
| assert commit_c.author is not None | ||
| assert commit_c.author.id == existing_author.id | ||
|
|
||
| commit_d = Commit.objects.get(repository_id=repo.id, key="d" * 40) | ||
| assert commit_d.author is None | ||
|
|
||
|
|
||
| class SetRefsTest(SetRefsTestCase): | ||
| def setUp(self) -> None: | ||
|
|
||
Oops, something went wrong.
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.
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.
Up to you but worth adding a test to verify the batching behavior or anything else related to commit authors?