Skip to content
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

Bulk insert members and member_roles for sub projects #26

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sanak
Copy link
Owner

@sanak sanak commented Aug 26, 2024

Performance up patch for many sub projects and members.
TODO:

@sanak sanak self-assigned this Aug 26, 2024
@sanak
Copy link
Owner Author

sanak commented Aug 29, 2024

bullet gem reports the following log when changing parent project, so consider to follow advice.

user: sanak
PATCH /projects/sub-project-1-2
USE eager loading detected
  Member => [:member_roles]
  Add to your query: .includes([:member_roles])
Call stack
  /Users/sanak/Build/rb/redmine/app/models/project.rb:1074:in `block (2 levels) in add_inherited_member_roles'
  /Users/sanak/Build/rb/redmine/app/models/project.rb:1071:in `block in add_inherited_member_roles'
  /Users/sanak/Build/rb/redmine/app/models/project.rb:1057:in `add_inherited_member_roles'
  /Users/sanak/Build/rb/redmine/app/controllers/projects_controller.rb:216:in `update'
  /Users/sanak/Build/rb/redmine/lib/redmine/sudo_mode.rb:78:in `sudo_mode'

Also, consider to cache (or merge) bulk insert result returning ids not to execute find_by query again.

        parent.memberships.each do |parent_member|
          member = Member.find_or_initialize_by(:project_id => self.id, :user_id => parent_member.user_id)
          :
        parent.memberships.each do |parent_member|
          # Member should exist
          member = Member.find_by(:project_id => self.id, :user_id => parent_member.user_id)
          parent_member.member_roles.each do |parent_member_role|
          :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant