use relation org.plans instead of method, which works faster and more correct#2726
use relation org.plans instead of method, which works faster and more correct#2726briri merged 7 commits intoDMPRoadmap:developmentfrom nicolasfranck:fix_issue_2724
Conversation
|
mm, there seems to be something wrong with the integration tests for postgresql and mysql.. |
|
it looks like there was a change to the way GitHub actions wants us to dynamically set env variables. I have submitted a fix for this in #2728. The dev team will be reviewing these PRs tomorrow. |
|
Hi @nicolasfranck and thanks for sending these PRs over! We are a small team so your contributions and suggestions are appreciated. The A quick search shows it is used for statistics, security policies, UI navigation logic, and the API: > grep -r 'rg\.plans' app
app/models/plan.rb: plan_ids = user.org.plans.where(complete: true).pluck(:id).uniq
app/policies/api/v1/plans_policy.rb: ids += client.org.plans.organisationally_visible.pluck(:id)
app/policies/api/v1/plans_policy.rb: ids += client.org.plans.pluck(:id) if client.can_org_admin?
app/policies/plan_policy.rb: @user.org.plans.include?(@plan))
app/controllers/paginable/plans_controller.rb: plans = @super_admin ? Plan.all : current_user.org.plans
app/controllers/api/v0/statistics_controller.rb: @user.org.plans.where(complete: true)
app/controllers/api/v0/statistics_controller.rb: @user.org.plans
app/controllers/api/v0/statistics_controller.rb: scoped = @user.org.plans
app/controllers/api/v0/statistics_controller.rb: @org_plans = @user.org.plans
app/controllers/api/v0/plans_controller.rb: @plans = @user.org.plans.includes([{ roles: :user }, { answers: :question_options },
app/controllers/org_admin/plans_controller.rb: @plans = @super_admin ? Plan.all.page(1) : current_user.org.plans.page(1)
app/controllers/org_admin/plans_controller.rb: org.plans.includes(template: :org).order(updated_at: :desc).each do |plan|
app/views/plans/_navigation.html.erb: <% if plan.administerable_by?(current_user) || (current_user.can_org_admin? && current_user.org.plans.include?(plan)) %>
app/views/plans/_navigation.html.erb: <% if (plan.administerable_by?(current_user) || (current_user.can_org_admin? && current_user.org.plans.include?(plan))) && plan.owner_and_coowners.include?(current_user) && plan.owner.org.feedback_enabled? %>We agree that |
|
Updating this PR as well, see #2741 (comment) for details |
…and more correct" This reverts commit 8d17654.
|
Ok, now it works like before, but now |
xsrust
left a comment
There was a problem hiding this comment.
Thanks @nicolasfranck
I think the cache approach should alleviate some of the performance issues in the meantime, but longer-term we should definitely consider making this a custom-relationship and renaming to something like org.plans_where_administrator (or something more concise) and then defining org.plans through the association.
| .pluck(:plan_id).uniq | ||
| Plan.includes(:template, :phases, :roles, :users) | ||
| .where(id: plan_ids) | ||
| Rails.cache.fetch("org[#{id}].plans", expires_in: 2.seconds) do |
There was a problem hiding this comment.
👍 I think this approach can be useful elsewhere as well.
|
|
use relation org.plans instead of method, which works faster and more correct
Fixes issue #2724 .