BigW Consortium Gitlab

Commit 64c2bccd by Dmitriy Zaporozhets

Merge branch 'fix-issue-3067' into 'master'

Fix nonatomic database update potentially causing project star counts to go negative The `counter_cache` decrement function is called when a project star is deleted, but there was no guarantee multiple workers would not attempt to delete the same item simultaneously. Use an atomic update to prevent the count from going negative. Note: I was only able to duplicate the issue on GitLab.com, but I haven't been able to replicate it anywhere else. Presumably this bug happens when the `WHERE` clause takes some time to search for the right entry and multiple requests get sent simultaneously. Need to verify whether this fix truly solves the issue. Closes #3067 See merge request !1628
parents 5ad3a274 ca3ce5c2
...@@ -5,6 +5,7 @@ v 8.2.0 (unreleased) ...@@ -5,6 +5,7 @@ v 8.2.0 (unreleased)
- Highlight comment based on anchor in URL - Highlight comment based on anchor in URL
v 8.1.0 (unreleased) v 8.1.0 (unreleased)
- Fix nonatomic database update potentially causing project star counts to go negative (Stan Hu)
- Fix error preventing displaying of commit data for a directory with a leading dot (Stan Hu) - Fix error preventing displaying of commit data for a directory with a leading dot (Stan Hu)
- Speed up load times of issue detail pages by roughly 1.5x - Speed up load times of issue detail pages by roughly 1.5x
- Add a system note and update relevant merge requests when a branch is deleted or re-added (Stan Hu) - Add a system note and update relevant merge requests when a branch is deleted or re-added (Stan Hu)
......
...@@ -706,12 +706,15 @@ class User < ActiveRecord::Base ...@@ -706,12 +706,15 @@ class User < ActiveRecord::Base
end end
def toggle_star(project) def toggle_star(project)
user_star_project = users_star_projects. UsersStarProject.transaction do
where(project: project, user: self).take user_star_project = users_star_projects.
if user_star_project where(project: project, user: self).lock(true).first
user_star_project.destroy
else if user_star_project
UsersStarProject.create!(project: project, user: self) user_star_project.destroy
else
UsersStarProject.create!(project: project, user: self)
end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment