Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-11 09:06:27 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-11 09:06:27 +0300
commitb4e072cbaf808793bafff148b0ec9d47819f479e (patch)
treec690c706803cf43b3358785681e693ea0e1f9f94 /app
parent8c0166b9816477521bf34feb15575bbeb1a3c644 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/controllers/groups_controller.rb20
-rw-r--r--app/models/clusters/applications/cert_manager.rb2
-rw-r--r--app/models/event.rb9
-rw-r--r--app/models/event_collection.rb43
-rw-r--r--app/models/group.rb4
-rw-r--r--app/views/groups/_activities.html.haml2
-rw-r--r--app/views/shared/_event_filter.html.haml4
7 files changed, 46 insertions, 38 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 95a7876a055..3204e1e388b 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -198,15 +198,13 @@ class GroupsController < Groups::ApplicationController
def load_events
params[:sort] ||= 'latest_activity_desc'
- options = {}
- options[:include_subgroups] = true
-
- @projects = GroupProjectsFinder.new(params: params, group: group, options: options, current_user: current_user)
- .execute
- .includes(:namespace)
+ options = { include_subgroups: true }
+ projects = GroupProjectsFinder.new(params: params, group: group, options: options, current_user: current_user)
+ .execute
+ .includes(:namespace)
@events = EventCollection
- .new(@projects, offset: params[:offset].to_i, filter: event_filter)
+ .new(projects, offset: params[:offset].to_i, filter: event_filter, groups: groups)
.to_a
Events::RenderService
@@ -228,6 +226,14 @@ class GroupsController < Groups::ApplicationController
url_for(safe_params)
end
+
+ private
+
+ def groups
+ if @group.supports_events?
+ @group.self_and_descendants.public_or_visible_to_user(current_user)
+ end
+ end
end
GroupsController.prepend_if_ee('EE::GroupsController')
diff --git a/app/models/clusters/applications/cert_manager.rb b/app/models/clusters/applications/cert_manager.rb
index 27d4180e5b9..2d71c4d5754 100644
--- a/app/models/clusters/applications/cert_manager.rb
+++ b/app/models/clusters/applications/cert_manager.rb
@@ -65,7 +65,7 @@ module Clusters
end
def retry_command(command)
- "for i in $(seq 1 30); do #{command} && break; sleep 1s; echo \"Retrying ($i)...\"; done"
+ "for i in $(seq 1 30); do #{command} && break; sleep 1s; echo \"Retrying ($i)...\"; false; done"
end
def post_delete_script
diff --git a/app/models/event.rb b/app/models/event.rb
index 205e1f71c74..9611019adb8 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -77,15 +77,6 @@ class Event < ApplicationRecord
scope :recent, -> { reorder(id: :desc) }
scope :code_push, -> { where(action: PUSHED) }
- scope :in_projects, -> (projects) do
- sub_query = projects
- .except(:order)
- .select(1)
- .where('projects.id = events.project_id')
-
- where('EXISTS (?)', sub_query).recent
- end
-
scope :with_associations, -> do
# We're using preload for "push_event_payload" as otherwise the association
# is not always available (depending on the query being built).
diff --git a/app/models/event_collection.rb b/app/models/event_collection.rb
index a4c69b11781..4778f74568e 100644
--- a/app/models/event_collection.rb
+++ b/app/models/event_collection.rb
@@ -6,6 +6,8 @@
# in a controller), it's not suitable for building queries that are used for
# building other queries.
class EventCollection
+ include Gitlab::Utils::StrongMemoize
+
# To prevent users from putting too much pressure on the database by cycling
# through thousands of events we put a limit on the number of pages.
MAX_PAGE = 10
@@ -13,57 +15,52 @@ class EventCollection
# projects - An ActiveRecord::Relation object that returns the projects for
# which to retrieve events.
# filter - An EventFilter instance to use for filtering events.
- def initialize(projects, limit: 20, offset: 0, filter: nil)
+ def initialize(projects, limit: 20, offset: 0, filter: nil, groups: nil)
@projects = projects
@limit = limit
@offset = offset
@filter = filter
+ @groups = groups
end
# Returns an Array containing the events.
def to_a
return [] if current_page > MAX_PAGE
- relation = if Gitlab::Database.join_lateral_supported?
- relation_with_join_lateral
+ relation = if groups
+ project_and_group_events
else
- relation_without_join_lateral
+ relation_with_join_lateral('project_id', projects)
end
+ relation = paginate_events(relation)
relation.with_associations.to_a
end
private
- # Returns the events relation to use when JOIN LATERAL is not supported.
- #
- # This relation simply gets all the events for all authorized projects, then
- # limits that set.
- def relation_without_join_lateral
- events = filtered_events.in_projects(projects)
+ def project_and_group_events
+ project_events = relation_with_join_lateral('project_id', projects)
+ group_events = relation_with_join_lateral('group_id', groups)
- paginate_events(events)
+ Event.from_union([project_events, group_events]).recent
end
- # Returns the events relation to use when JOIN LATERAL is supported.
- #
# This relation is built using JOIN LATERAL, producing faster queries than a
# regular LIMIT + OFFSET approach.
- def relation_with_join_lateral
- projects_for_lateral = projects.select(:id).to_sql
+ def relation_with_join_lateral(parent_column, parents)
+ parents_for_lateral = parents.select(:id).to_sql
lateral = filtered_events
.limit(limit_for_join_lateral)
- .where('events.project_id = projects_for_lateral.id')
+ .where("events.#{parent_column} = parents_for_lateral.id") # rubocop:disable GitlabSecurity/SqlInjection
.to_sql
# The outer query does not need to re-apply the filters since the JOIN
# LATERAL body already takes care of this.
- outer = base_relation
- .from("(#{projects_for_lateral}) projects_for_lateral")
+ base_relation
+ .from("(#{parents_for_lateral}) parents_for_lateral")
.joins("JOIN LATERAL (#{lateral}) AS #{Event.table_name} ON true")
-
- paginate_events(outer)
end
def filtered_events
@@ -97,4 +94,10 @@ class EventCollection
def projects
@projects.except(:order)
end
+
+ def groups
+ strong_memoize(:groups) do
+ groups.except(:order) if @groups
+ end
+ end
end
diff --git a/app/models/group.rb b/app/models/group.rb
index 5df9d97dcb6..0501fe94440 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -436,6 +436,10 @@ class Group < Namespace
members.owners.order_recent_sign_in.limit(ACCESS_REQUEST_APPROVERS_TO_BE_NOTIFIED_LIMIT)
end
+ def supports_events?
+ false
+ end
+
private
def update_two_factor_requirement
diff --git a/app/views/groups/_activities.html.haml b/app/views/groups/_activities.html.haml
index 13df1e57125..44554cab1e9 100644
--- a/app/views/groups/_activities.html.haml
+++ b/app/views/groups/_activities.html.haml
@@ -1,5 +1,5 @@
.nav-block.activities
- = render 'shared/event_filter'
+ = render 'shared/event_filter', show_group_events: @group.supports_events?
.controls
= link_to group_path(@group, rss_url_options), class: 'btn d-none d-sm-inline-block has-tooltip' , title: 'Subscribe' do
%i.fa.fa-rss
diff --git a/app/views/shared/_event_filter.html.haml b/app/views/shared/_event_filter.html.haml
index 6612497e7e2..ad9eb325ff0 100644
--- a/app/views/shared/_event_filter.html.haml
+++ b/app/views/shared/_event_filter.html.haml
@@ -1,3 +1,5 @@
+- show_group_events = local_assigns.fetch(:show_group_events, false)
+
.scrolling-tabs-container.inner-page-scroll-tabs.is-smaller.flex-fill
.fade-left= icon('angle-left')
.fade-right= icon('angle-right')
@@ -9,6 +11,8 @@
= event_filter_link EventFilter::MERGED, _('Merge events'), s_('EventFilterBy|Filter by merge events')
- if event_filter_visible(:issues)
= event_filter_link EventFilter::ISSUE, _('Issue events'), s_('EventFilterBy|Filter by issue events')
+ - if show_group_events
+ = render_if_exists 'events/epics_filter'
- if comments_visible?
= event_filter_link EventFilter::COMMENTS, _('Comments'), s_('EventFilterBy|Filter by comments')
= event_filter_link EventFilter::TEAM, _('Team'), s_('EventFilterBy|Filter by team')