From: David Gageot Date: Sat, 6 Oct 2012 08:21:18 +0000 (+0200) Subject: Optimize Rails models X-Git-Tag: 3.3~92 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c7773cfab68b32bcba0e9a129fdb04ce43cc5774;p=sonarqube.git Optimize Rails models --- diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb index a0ff3cb54ea..cd29bd2cb6e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb @@ -24,7 +24,7 @@ class Dashboard < ActiveRecord::Base belongs_to :user has_many :widgets, :include => 'properties', :dependent => :destroy - has_many :active_dashboards, :dependent => :destroy + has_many :active_dashboards, :dependent => :destroy, :inverse_of => :dashboard validates_length_of :name, :within => 1..256 validates_length_of :description, :maximum => 1000, :allow_blank => true, :allow_nil => true diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb index ec7e9c2b622..8b55ca33938 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb @@ -24,11 +24,11 @@ class Rule < ActiveRecord::Base validates_presence_of :name, :description, :plugin_name validates_presence_of :plugin_rule_key, :if => 'name.present?' - has_many :rules_parameters - has_many :rule_failures - has_many :active_rules + has_many :rules_parameters, :inverse_of => :rule + has_many :rule_failures, :inverse_of => :rule + has_many :active_rules, :inverse_of => :rule belongs_to :parent, :class_name => 'Rule', :foreign_key => 'parent_id' - has_one :rule_note + has_one :rule_note, :inverse_of => :rule alias_attribute :note, :rule_note def repository_key diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rules_parameter.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rules_parameter.rb index 0979374d445..afee77ecbf4 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rules_parameter.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rules_parameter.rb @@ -33,17 +33,6 @@ class RulesParameter < ActiveRecord::Base param_type[2, param_type.length-3].split(",") end - # We can provide the rule as parameter to avoid reloading this rule_parameter's rule. - # This hack would be useless if we could use :inverse_of on :rule - def description(param_rule = rule) - @l10n_description ||= - begin - result = Java::OrgSonarServerUi::JRubyFacade.getInstance().getRuleParamDescription(I18n.locale, param_rule.repository_key, param_rule.plugin_rule_key, name()) - result = read_attribute(:description) unless result - result - end - end - def description=(value) write_attribute(:description, value) end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/widget.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/widget.rb index 61a5d51e0d2..76766b13e5d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/widget.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/widget.rb @@ -18,7 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # class Widget < ActiveRecord::Base - has_many :properties, :dependent => :delete_all, :class_name => 'WidgetProperty' + has_many :properties, :dependent => :delete_all, :class_name => 'WidgetProperty', :inverse_of => :widget belongs_to :dashboards belongs_to :resource, :class_name => 'Project' diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb index 12cb97238c1..7e35b07abd5 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb @@ -40,7 +40,7 @@ <% end %> <% end %> -
<%= h(parameter.description(rule) || "") -%> <%= ('(' + readable_type(parameter.param_type) + ')') if !readable_type(parameter.param_type).empty? -%>
+
<%= h(parameter.rule.description || "") -%> <%= ('(' + readable_type(parameter.param_type) + ')') if !readable_type(parameter.param_type).empty? -%>