diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-06-29 14:38:30 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-07-04 10:25:05 +0200 |
commit | 129eab1c1e69df45c733a3a08e296b6bd819fb3b (patch) | |
tree | be5fc8954a8b78002ae4963a744249bd1bf142b9 /server/sonar-web/src/main/webapp | |
parent | 99cd64a81ef9e9e156bb0d69b2aa662d59bf71a1 (diff) | |
download | sonarqube-129eab1c1e69df45c733a3a08e296b6bd819fb3b.tar.gz sonarqube-129eab1c1e69df45c733a3a08e296b6bd819fb3b.zip |
SONAR-7780 Stop using PROJECT_MEASURES.SNAPSHOT_ID
Diffstat (limited to 'server/sonar-web/src/main/webapp')
9 files changed, 84 insertions, 81 deletions
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' - "<span class='small'>#{row.snapshot.resource.kee}</span>" + "<span class='small'>#{row.resource.kee}</span>" 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 @@ -40,6 +40,11 @@ class MeasureFilter < ActiveRecord::Base end # For internal use + def set_analysis(analysis) + @analysis=analysis + end + + # For internal use def add_link(link) @links ||= [] @links << link @@ -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<rows.size) + component_uuids = rows.map { |row| row.getComponentUuid() if authorized_project_uuids.include?(row.getRootComponentUuid()) }.compact + @security_exclusions = (component_uuids.size<rows.size) @pagination = Api::Pagination.new @pagination.per_page=(criteria(:pageSize)||999999).to_i @pagination.page=(criteria(:page)||1).to_i - @pagination.count = snapshot_ids.size - snapshot_ids[@pagination.offset ... (@pagination.offset+@pagination.limit)] || [] + @pagination.count = component_uuids.size + component_uuids[@pagination.offset ... (@pagination.offset+@pagination.limit)] || [] end - def load_results(snapshot_ids, base_resource) + def load_results(component_uuids, base_resource) @rows = [] metric_ids = metrics.map(&:id) - if !snapshot_ids.empty? - rows_by_snapshot_id = {} + if !component_uuids.empty? + rows_by_component_uuid = {} + + components = [] + component_uuids.each_slice(999) do |safe_for_oracle_uuids| + components.concat(Project.find(:all, :conditions => ['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| %> <tr class="thin <%= cycle 'even', 'odd' -%>"> <% if display_favourites %> - <td class="thin"><%= link_to_favourite(row.snapshot.resource) -%></td> + <td class="thin"><%= link_to_favourite(row.resource) -%></td> <% end %> <td class="nowrap"> - <%= 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)) -%> </td> <td class="sep"></td> <td> - <%= h row.snapshot.resource.description -%> + <%= h row.resource.description -%> </td> <td class="sep"></td> <td class="nowrap text-right"> 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 %> <tr class="highlight"> <% if display_favourites %> - <td class="thin"><%= link_to_favourite(filter.base_row.snapshot.resource) -%></td> + <td class="thin"><%= link_to_favourite(filter.base_row.resource) -%></td> <% end %> <% filter.display.columns.each do |column| %> <td class="<%= column.align -%> <%= column.row_css -%>"> @@ -201,7 +201,7 @@ <% filter.rows.each do |row| %> <tr class="<%= cycle 'even', 'odd' -%>"> <% if display_favourites %> - <td class="thin"><%= link_to_favourite(row.snapshot.resource) -%></td> + <td class="thin"><%= link_to_favourite(row.resource) -%></td> <% end %> <% filter.display.columns.each do |column| %> <td class="<%= column.align -%> <%= column.row_css -%>"> 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} %> <tr class="<%= cycle 'even','odd' -%> snapshot"> @@ -66,9 +66,9 @@ <td class="small edit_actions" style="padding-left:20px"> <a id="version_<%= index -%>_change" href="#" onclick="$j('#version_<%= index -%>').hide();$j('#version_<%= index -%>_form').show();$j('#version_name_<%= index -%>').focus();return false;"><%= message('project_history.rename_version') -%></a> - <% 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 %> </td> @@ -82,7 +82,7 @@ </tr> <tr id="version_<%= index -%>_form" style="display:none;"> <td coslpan="2" class="admin"> - <% form_tag( {:action => 'update_version', :sid => snapshot.id }) do -%> + <% form_tag( {:action => 'update_version', :sid => analysis.id }) do -%> <input id="version_name_<%= index -%>" name="version_name" type="text" value="<%= version_event ? h(version_event.name) : '' -%>" onKeyUp="if (this.value=='') $j('#save_version_<%= index -%>').disabled='true'; else $j('#save_version_<%= index -%>').disabled='';"/> <%= submit_tag message('save'), :id => 'save_version_' + index.to_s %> @@ -127,7 +127,7 @@ </tr> <tr id="create_event_<%= index -%>_form" style="display:none;"> <td colspan="2" class="admin"> - <% form_tag( {:action => 'create_event', :sid => snapshot.id }) do -%> + <% form_tag( {:action => 'create_event', :sid => analysis.id }) do -%> <input id="create_event_name_<%= index -%>" name="event_name" type="text" value="" onKeyUp="if (this.value=='') $j('#create_save_event_<%= index -%>').disabled='true'; else $j('#create_save_event_<%= index -%>').disabled='';"/> <%= submit_tag message('save'), :id => 'create_save_event_' + index.to_s %> @@ -149,11 +149,11 @@ <td class="thin nowrap text-right" style="padding-left:10px; padding-right:10px"> <% cell_content = nil; - if snapshot.islast? + if analysis.islast? cell_content = "<b>" + message('project_history.last_snapshot') + "</b>" 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 |