From 129eab1c1e69df45c733a3a08e296b6bd819fb3b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 29 Jun 2016 14:38:30 +0200 Subject: SONAR-7780 Stop using PROJECT_MEASURES.SNAPSHOT_ID --- .../WEB-INF/app/controllers/measures_controller.rb | 6 +- .../WEB-INF/app/controllers/project_controller.rb | 4 +- .../webapp/WEB-INF/app/helpers/measures_helper.rb | 16 ++-- .../webapp/WEB-INF/app/models/measure_filter.rb | 95 ++++++++++++---------- .../src/main/webapp/WEB-INF/app/models/project.rb | 1 - .../webapp/WEB-INF/app/models/project_measure.rb | 9 +- .../WEB-INF/app/views/all_projects/index.html.erb | 6 +- .../app/views/measures/_display_list.html.erb | 4 +- .../WEB-INF/app/views/project/history.html.erb | 24 +++--- 9 files changed, 84 insertions(+), 81 deletions(-) (limited to 'server/sonar-web/src/main/webapp') diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb index c952c7d838c..de7a8665353 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb @@ -252,15 +252,15 @@ class MeasuresController < ApplicationController hash = {} components_json = [] filter.rows.each do |row| - component = row.snapshot.resource + component = row.resource component_hash = {} component_hash[:key] = component.key component_hash[:name] = component.name if fields.include?('name') && component.name component_hash[:longName] = component.long_name if fields.include?('longName') && component.long_name component_hash[:qualifier] = component.qualifier if component.qualifier component_hash[:favorite] = logged_in? && current_user.favourite?(component.id) if fields.include?('favourite') - component_hash[:date] = Api::Utils.format_datetime(row.snapshot.created_at) if fields.include?('date') && row.snapshot.created_at - component_hash[:fdate] = human_short_date(row.snapshot.created_at) if fields.include?('date') && row.snapshot.created_at + component_hash[:date] = Api::Utils.format_datetime(row.analysis.created_at) if fields.include?('date') && row.analysis.created_at + component_hash[:fdate] = human_short_date(row.analysis.created_at) if fields.include?('date') && row.analysis.created_at if display_links && row.links links_hash = {} diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb index 9215bbe1934..bcf3c53455c 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb @@ -218,8 +218,8 @@ class ProjectController < ApplicationController redirect_to :action => 'index', :id => params[:id] end - @snapshot=@project.last_snapshot - @snapshots = Snapshot.all(:conditions => ["status='P' AND component_uuid=?", @project.uuid], + @snapshot = @project.last_snapshot + @analyses = Snapshot.all(:conditions => ["status='P' AND component_uuid=?", @project.uuid], :include => 'events', :order => 'snapshots.created_at DESC') end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb index 6bc58c10ec4..7e75a3701ed 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb @@ -48,21 +48,21 @@ module MeasuresHelper end elsif column.key=='name' - "#{qualifier_icon(row.snapshot)} #{link_to(h(row.snapshot.resource.name(true)), {:controller => 'dashboard', :id => row.snapshot.resource_id}, {:title => h(row.snapshot.resource.key)})}" + "#{qualifier_icon(row.resource)} #{link_to(h(row.resource.name(true)), {:controller => 'dashboard', :id => row.resource.id}, {:title => h(row.resource.key)})}" elsif column.key=='short_name' - "#{qualifier_icon(row.snapshot)} #{link_to(h(row.snapshot.resource.name(false)), {:controller => 'dashboard', :id => row.snapshot.resource_id}, {:title => h(row.snapshot.resource.key)})}" + "#{qualifier_icon(row.resource)} #{link_to(h(row.resource.name(false)), {:controller => 'dashboard', :id => row.resource.id}, {:title => h(row.resource.key)})}" elsif column.key=='date' - human_short_date(row.snapshot.created_at) + human_short_date(row.analysis.created_at) if row.analysis elsif column.key=='project_creation_date' - human_short_date(row.snapshot.resource.created_at) if row.snapshot.resource.created_at + human_short_date(row.resource.created_at) if row.resource.created_at elsif column.key=='key' - "#{row.snapshot.resource.kee}" + "#{row.resource.kee}" elsif column.key=='description' - h row.snapshot.resource.description + h row.resource.description elsif column.key=='version' - h row.snapshot.version + h row.analysis.version if row.analysis elsif column.key=='language' - Api::Utils.language_name(row.snapshot.resource.language) + Api::Utils.language_name(row.resource.language) elsif column.key=='links' && row.links html = '' row.links.select { |link| link.href.start_with?('http') }.each do |link| diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb index 97a4942536f..a45fdf9565d 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb @@ -22,16 +22,16 @@ class MeasureFilter < ActiveRecord::Base # Row in the table of results class Row - attr_reader :snapshot, :measures_by_metric, :links + attr_reader :component, :measures_by_metric, :links, :analysis - def initialize(snapshot) - @snapshot = snapshot + def initialize(component) + @component = component @measures_by_metric = {} @links = nil end def resource - snapshot.resource + component end # For internal use @@ -39,6 +39,11 @@ class MeasureFilter < ActiveRecord::Base @measures_by_metric[measure.metric] = measure end + # For internal use + def set_analysis(analysis) + @analysis=analysis + end + # For internal use def add_link(link) @links ||= [] @@ -208,9 +213,9 @@ class MeasureFilter < ActiveRecord::Base errors.add_to_base(Api::Utils.message("measure_filter.error.#{result.error}")) else rows = result.getRows() - snapshot_ids = filter_authorized_snapshot_ids(rows, controller) + component_uuids = filter_authorized_component_uuids(rows, controller) base_project = filter_authorized_base_project(base_resource, controller) - load_results(snapshot_ids, base_project) + load_results(component_uuids, base_project) end self end @@ -240,76 +245,82 @@ class MeasureFilter < ActiveRecord::Base controller.has_role?(:user, base_resource) ? base_resource : nil end - def filter_authorized_snapshot_ids(rows, controller) + def filter_authorized_component_uuids(rows, controller) project_uuids = rows.map { |row| row.getRootComponentUuid() }.compact.uniq authorized_project_uuids = controller.select_authorized(:user, project_uuids) - snapshot_ids = rows.map { |row| row.getSnapshotId() if authorized_project_uuids.include?(row.getRootComponentUuid()) }.compact - @security_exclusions = (snapshot_ids.size ['uuid in (?)', safe_for_oracle_uuids])) + end + project_uuids = [] + components.each do |component| + row = Row.new(component) + rows_by_component_uuid[component.uuid] = row + project_uuids << component.project_uuid + end + project_uuids.uniq! - snapshots = [] - snapshot_ids.each_slice(999) do |safe_for_oracle_ids| - snapshots.concat(Snapshot.all(:include => ['project'], :conditions => ['id in (?)', safe_for_oracle_ids])) + analysis_by_project_uuid = Snapshot.all(:conditions => ['component_uuid in (?) and islast=?', project_uuids, true]).inject({}) do |hash, analysis| + hash[analysis.component_uuid] = analysis + hash end - snapshots.each do |snapshot| - row = Row.new(snapshot) - rows_by_snapshot_id[snapshot.id] = row + + components.each do |component| + analysis = analysis_by_project_uuid[component.project_uuid] + rows_by_component_uuid[component.uuid].set_analysis(analysis) if analysis end - # @rows must be in the same order than the snapshot ids - snapshot_ids.each do |sid| - @rows << rows_by_snapshot_id[sid] + # @rows must be in the same order than the component uuids + component_uuids.each do |uuid| + @rows << rows_by_component_uuid[uuid] end unless metric_ids.empty? measures = [] - snapshot_ids.each_slice(999) do |safe_for_oracle_ids| - measures.concat(ProjectMeasure.all(:conditions => - ['person_id is null and snapshot_id in (?) and metric_id in (?)', safe_for_oracle_ids, metric_ids] + component_uuids.each_slice(999) do |safe_for_oracle_uuids| + measures.concat(ProjectMeasure.all(:include => :analysis, :conditions => + ['project_measures.person_id is null and project_measures.component_uuid in (?) and project_measures.metric_id in (?) and snapshots.islast=?', safe_for_oracle_uuids, metric_ids, true] )) end measures.each do |measure| - row = rows_by_snapshot_id[measure.snapshot_id] + row = rows_by_component_uuid[measure.component_uuid] row.add_measure(measure) end end if require_links? - project_uuids = [] - rows_by_project_uuid = {} - snapshots.each do |snapshot| - project_uuids << snapshot.component_uuid - rows_by_project_uuid[snapshot.component_uuid] = rows_by_snapshot_id[snapshot.id] - end + uuids_for_links = components.map { |c| c.uuid if c.scope=='PRJ'}.compact.uniq - links = [] - project_uuids.each_slice(999) do |safe_for_oracle_uuids| - links.concat(ProjectLink.all(:conditions => {:component_uuid => safe_for_oracle_uuids}, :order => 'link_type')) - end - links.each do |link| - rows_by_project_uuid[link.component_uuid].add_link(link) + uuids_for_links.each_slice(999) do |safe_for_oracle_uuids| + ProjectLink.all(:conditions => {:component_uuid => safe_for_oracle_uuids}, :order => 'link_type').each do |link| + rows_by_component_uuid[link.component_uuid].add_link(link) + end end end end if base_resource base_snapshot = base_resource.last_snapshot if base_snapshot - @base_row = Row.new(base_snapshot) + @base_row = Row.new(base_resource) unless metric_ids.empty? - base_measures = ProjectMeasure.all(:conditions => - ['person_id is null and snapshot_id=? and metric_id in (?)', base_snapshot.id, metric_ids] + base_measures = ProjectMeasure.all(:include => :analysis, :conditions => + ['project_measures.person_id is null and project_measures.component_uuid=? and project_measures.metric_id in (?) and snapshots.islast=?', base_resource.uuid, metric_ids, true] ) base_measures.each do |base_measure| @base_row.add_measure(base_measure) diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb index 1f008742a8e..7a631651f7e 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb @@ -22,7 +22,6 @@ class Project < ActiveRecord::Base include Resourceable has_many :snapshots, :class_name => 'Snapshot', :foreign_key => 'component_uuid', :primary_key => 'uuid' - has_many :processed_snapshots, :class_name => 'Snapshot', :foreign_key => 'component_uuid', :primary_key => 'uuid', :conditions => "status='#{Snapshot::STATUS_PROCESSED}' AND qualifier<>'LIB'", :order => 'created_at asc' has_many :events, :foreign_key => 'component_uuid', :primary_key => 'uuid', :order => 'event_date DESC' has_many :project_links, :foreign_key => 'component_uuid', :primary_key => 'uuid', :dependent => :delete_all, :order => 'link_type' has_many :user_roles, :foreign_key => 'resource_id' diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_measure.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_measure.rb index 526b10d63ae..34362d2f5bd 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_measure.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_measure.rb @@ -25,6 +25,7 @@ class ProjectMeasure < ActiveRecord::Base HOUR = 1000 * 60 * 60 DAY = 1000 * 60 * 60 * 24 + belongs_to :analysis, :class_name => 'Snapshot', :foreign_key => 'analysis_uuid', :primary_key => 'uuid' belongs_to :snapshot belongs_to :project, :class_name => 'Project', :foreign_key => 'component_uuid', :primary_key => 'uuid' belongs_to :person, :class_name => 'Project', :foreign_key => 'person_id' @@ -213,14 +214,6 @@ class ProjectMeasure < ActiveRecord::Base end end - def tip - snapshot.project.tip - end - - def self.find_by_metrics_and_snapshots(metric_ids, snapshot_ids) - ProjectMeasure.find(:all, :conditions => {:snapshot_id => snapshot_ids, :metric_id => metric_ids}) - end - def short_name metric.short_name end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/all_projects/index.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/all_projects/index.html.erb index 57f52ad30e8..b7bc5fd17ef 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/all_projects/index.html.erb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/all_projects/index.html.erb @@ -37,14 +37,14 @@ <% @filter.rows.each do |row| %> <% if display_favourites %> - <%= link_to_favourite(row.snapshot.resource) -%> + <%= link_to_favourite(row.resource) -%> <% end %> - <%= qualifier_icon(row.snapshot) -%> <%= link_to(h(row.snapshot.resource.name(true)), {:controller => 'dashboard', :id => row.snapshot.resource_id}, :title => h(row.snapshot.resource.key)) -%> + <%= qualifier_icon(row.resource) -%> <%= link_to(h(row.resource.name(true)), {:controller => 'dashboard', :id => row.resource.id}, :title => h(row.resource.key)) -%> - <%= h row.snapshot.resource.description -%> + <%= h row.resource.description -%> diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb index 58626284c2f..c3e904234bf 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb @@ -188,7 +188,7 @@ <% if filter.base_row %> <% if display_favourites %> - <%= link_to_favourite(filter.base_row.snapshot.resource) -%> + <%= link_to_favourite(filter.base_row.resource) -%> <% end %> <% filter.display.columns.each do |column| %> @@ -201,7 +201,7 @@ <% filter.rows.each do |row| %> <% if display_favourites %> - <%= link_to_favourite(row.snapshot.resource) -%> + <%= link_to_favourite(row.resource) -%> <% end %> <% filter.display.columns.each do |column| %> diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/project/history.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/project/history.html.erb index a3bce339e61..080cbe7523d 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/project/history.html.erb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/project/history.html.erb @@ -35,12 +35,12 @@ <% current_year = nil current_month = nil - @snapshots.each_with_index do |snapshot, index| - time = snapshot.created_at - version_event = snapshot.event(EventCategory::KEY_VERSION) - alert_event = snapshot.event(EventCategory::KEY_ALERT) - profile_event = snapshot.event(EventCategory::KEY_PROFILE) - other_events = snapshot.events.select{|e| e.category!=EventCategory::KEY_VERSION && e.category!=EventCategory::KEY_ALERT && e.category!=EventCategory::KEY_PROFILE} + @analyses.each_with_index do |analysis, index| + time = analysis.created_at + version_event = analysis.event(EventCategory::KEY_VERSION) + alert_event = analysis.event(EventCategory::KEY_ALERT) + profile_event = analysis.event(EventCategory::KEY_PROFILE) + other_events = analysis.events.select{|e| e.category!=EventCategory::KEY_VERSION && e.category!=EventCategory::KEY_ALERT && e.category!=EventCategory::KEY_PROFILE} %> @@ -66,9 +66,9 @@ <%= message('project_history.rename_version') -%> - <% if version_event && !snapshot.islast? %> + <% if version_event && !analysis.islast? %> <%= link_to( message('project_history.remove_version'), - { :action => 'delete_version', :sid => snapshot.id}, + { :action => 'delete_version', :sid => analysis.id}, :confirm => message('project_history.do_you_want_to_remove_version', :params => version_event.name) ) -%> <% end %> @@ -82,7 +82,7 @@ - <% form_tag( {:action => 'update_version', :sid => snapshot.id }) do -%> + <% form_tag( {:action => 'update_version', :sid => analysis.id }) do -%> <%= submit_tag message('save'), :id => 'save_version_' + index.to_s %> @@ -127,7 +127,7 @@ - <% form_tag( {:action => 'create_event', :sid => snapshot.id }) do -%> + <% form_tag( {:action => 'create_event', :sid => analysis.id }) do -%> <%= submit_tag message('save'), :id => 'create_save_event_' + index.to_s %> @@ -149,11 +149,11 @@ <% cell_content = nil; - if snapshot.islast? + if analysis.islast? cell_content = "" + message('project_history.last_snapshot') + "" else cell_content = button_to( message('project_history.delete_snapshot'), - { :action => "delete_snapshot_history", :id => @project.id, :snapshot_id => snapshot.id }, + { :action => "delete_snapshot_history", :id => @project.id, :snapshot_id => analysis.id }, :class => 'button-red', :confirm => message('project_history.are_you_sure_delete_snapshot_x', :params => l(time, :format => :long)) ) end -- cgit v1.2.3