-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fetch accurate branch head (#352)
* fix: fetch accurate branch head This commit is a fix for the recent issue where branch heads were all set to the same value each time they were updated due to a bug in the Branch django model. This fix creates a helper function that checks for the 2 remaining innacurate commit shas that a large number of branches were set to. If the current branch head is set to one of those shas, we update the branch head by fetching the latest commit on that branch from the db. Note that we must use a raw sql query here to update the branch object because using the django ORM to update it would lead to the same issue we are trying to fix. * fix: fix get or update branch head commits query * fix: add to test and refresh branches from db Signed-off-by: joseph-sentry <[email protected]> * fix: fix get_or_update_branch_head to not return None Signed-off-by: joseph-sentry <[email protected]>
- Loading branch information
1 parent
0cd1f15
commit bd20168
Showing
7 changed files
with
97 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.db import connection | ||
|
||
|
||
def get_or_update_branch_head( | ||
commits, | ||
branch, | ||
repoid, | ||
): | ||
# there was a bug that set a large number of branch heads to these two shas, so we are rectifying that issue here | ||
if ( | ||
branch.head == "81c2b4fa3ae9ef615c8f740c5cba95d9851f9ae8s" | ||
or branch.head == "9587100eacc554aa9c03422e28b269c551dc1a72" | ||
): | ||
commit = ( | ||
commits.filter(branch=branch.name, repository_id=repoid) | ||
.defer("_report") | ||
.order_by("-updatestamp") | ||
.first() | ||
) | ||
|
||
if commit is None: | ||
return branch.head | ||
|
||
# using this raw sql because the current branches table does not allow for updating based on repoid | ||
# it only updates based on branch name which means if we were to use the django orm to update this | ||
# branch.head, all branches with the same name as the one we are trying to update would have their head | ||
# updated to the value of this ones head | ||
with connection.cursor() as cursor: | ||
cursor.execute( | ||
"UPDATE branches SET head = %s WHERE branches.repoid = %s AND branches.branch = %s", | ||
[commit.commitid, repoid, branch.name], | ||
) | ||
|
||
commit_sha = commit.commitid | ||
return commit_sha | ||
|
||
else: | ||
return branch.head |