Skip to content
Snippets Groups Projects
Commit 556c79d6 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent bffcdf9b
No related branches found
No related tags found
No related merge requests found
Showing
with 119 additions and 88 deletions
Loading
Loading
@@ -60,6 +60,7 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController
font
message
starts_at
target_path
))
end
end
Loading
Loading
@@ -28,7 +28,8 @@ class Admin::IdentitiesController < Admin::ApplicationController
 
def update
if @identity.update(identity_params)
RepairLdapBlockedUserService.new(@user).execute
::Users::RepairLdapBlockedService.new(@user).execute
redirect_to admin_user_identities_path(@user), notice: _('User identity was successfully updated.')
else
render :edit
Loading
Loading
@@ -37,7 +38,8 @@ class Admin::IdentitiesController < Admin::ApplicationController
 
def destroy
if @identity.destroy
RepairLdapBlockedUserService.new(@user).execute
::Users::RepairLdapBlockedService.new(@user).execute
redirect_to admin_user_identities_path(@user), status: :found, notice: _('User identity was successfully removed.')
else
redirect_to admin_user_identities_path(@user), status: :found, alert: _('Failed to remove user identity.')
Loading
Loading
# frozen_string_literal: true
 
module BroadcastMessagesHelper
def current_broadcast_messages
BroadcastMessage.current(request.path)
end
def broadcast_message(message)
return unless message.present?
 
Loading
Loading
Loading
Loading
@@ -20,7 +20,7 @@ class BroadcastMessage < ApplicationRecord
 
after_commit :flush_redis_cache
 
def self.current
def self.current(current_path = nil)
messages = cache.fetch(CACHE_KEY, as: BroadcastMessage, expires_in: cache_expires_in) do
current_and_future_messages
end
Loading
Loading
@@ -33,7 +33,7 @@ class BroadcastMessage < ApplicationRecord
# cache so we don't keep running this code all the time.
cache.expire(CACHE_KEY) if now_or_future.empty?
 
now_or_future.select(&:now?)
now_or_future.select(&:now?).select { |message| message.matches_current_path(current_path) }
end
 
def self.current_and_future_messages
Loading
Loading
@@ -72,6 +72,12 @@ class BroadcastMessage < ApplicationRecord
now? || future?
end
 
def matches_current_path(current_path)
return true if current_path.blank? || target_path.blank?
current_path.match(Regexp.escape(target_path).gsub('\\*', '.*'))
end
def flush_redis_cache
self.class.cache.expire(CACHE_KEY)
end
Loading
Loading
Loading
Loading
@@ -12,15 +12,18 @@ class MergeRequest::Pipelines
 
attr_reader :merge_request
 
delegate :all_commit_shas, :source_project, :source_branch, to: :merge_request
delegate :commit_shas, :source_project, :source_branch, to: :merge_request
 
def all
return Ci::Pipeline.none unless source_project
strong_memoize(:all_pipelines) do
pipelines = Ci::Pipeline.from_union(
[source_pipelines, detached_pipelines, triggered_for_branch],
remove_duplicates: false)
next Ci::Pipeline.none unless source_project
pipelines =
if merge_request.persisted?
pipelines_using_cte
else
triggered_for_branch.for_sha(commit_shas)
end
 
sort(pipelines)
end
Loading
Loading
@@ -28,38 +31,55 @@ class MergeRequest::Pipelines
 
private
 
def triggered_by_merge_request
source_project.ci_pipelines
.where(source: :merge_request_event, merge_request: merge_request)
def pipelines_using_cte
cte = Gitlab::SQL::CTE.new(:shas, merge_request.all_commits.select(:sha))
source_pipelines_join = cte.table[:sha].eq(Ci::Pipeline.arel_table[:source_sha])
source_pipelines = filter_by(triggered_by_merge_request, cte, source_pipelines_join)
detached_pipelines = filter_by_sha(triggered_by_merge_request, cte)
pipelines_for_branch = filter_by_sha(triggered_for_branch, cte)
Ci::Pipeline.with(cte.to_arel)
.from_union([source_pipelines, detached_pipelines, pipelines_for_branch])
end
def filter_by_sha(pipelines, cte)
hex = Arel::Nodes::SqlLiteral.new("'hex'")
string_sha = Arel::Nodes::NamedFunction.new('encode', [cte.table[:sha], hex])
join_condition = string_sha.eq(Ci::Pipeline.arel_table[:sha])
filter_by(pipelines, cte, join_condition)
end
 
def detached_pipelines
triggered_by_merge_request.for_sha(all_commit_shas)
def filter_by(pipelines, cte, join_condition)
shas_table =
Ci::Pipeline.arel_table
.join(cte.table, Arel::Nodes::InnerJoin)
.on(join_condition)
.join_sources
pipelines.joins(shas_table)
end
 
def source_pipelines
triggered_by_merge_request.for_source_sha(all_commit_shas)
def triggered_by_merge_request
source_project.ci_pipelines
.where(source: :merge_request_event, merge_request: merge_request)
end
 
def triggered_for_branch
source_project.ci_pipelines
.where(source: branch_pipeline_sources, ref: source_branch, tag: false)
.for_sha(all_commit_shas)
end
def sources
::Ci::Pipeline.sources
end
 
def branch_pipeline_sources
strong_memoize(:branch_pipeline_sources) do
sources.reject { |source| source == EVENT }.values
Ci::Pipeline.sources.reject { |source| source == EVENT }.values
end
end
 
def sort(pipelines)
sql = 'CASE ci_pipelines.source WHEN (?) THEN 0 ELSE 1 END, ci_pipelines.id DESC'
query = ApplicationRecord.send(:sanitize_sql_array, [sql, sources[:merge_request_event]]) # rubocop:disable GitlabSecurity/PublicSend
query = ApplicationRecord.send(:sanitize_sql_array, [sql, Ci::Pipeline.sources[:merge_request_event]]) # rubocop:disable GitlabSecurity/PublicSend
 
pipelines.order(Arel.sql(query))
end
Loading
Loading
# frozen_string_literal: true
class RepairLdapBlockedUserService
attr_accessor :user
def initialize(user)
@user = user
end
def execute
user.block if ldap_hard_blocked?
end
private
def ldap_hard_blocked?
user.ldap_blocked? && !user.ldap_user?
end
end
# frozen_string_literal: true
module Users
class RepairLdapBlockedService
attr_accessor :user
def initialize(user)
@user = user
end
def execute
user.block if ldap_hard_blocked?
end
private
def ldap_hard_blocked?
user.ldap_blocked? && !user.ldap_user?
end
end
end
Loading
Loading
@@ -38,6 +38,13 @@
= f.label :font, "Font Color"
.col-sm-10
= f.color_field :font, class: "form-control text-font-color"
.form-group.row
.col-sm-2.col-form-label
= f.label :target_path, _('Target Path')
.col-sm-10
= f.text_field :target_path, class: "form-control"
.form-text.text-muted
= _('Paths can contain wildcards, like */welcome')
.form-group.row
.col-sm-2.col-form-label
= f.label :starts_at, _("Starts at (UTC)")
Loading
Loading
Loading
Loading
@@ -19,6 +19,7 @@
%th Preview
%th Starts
%th Ends
%th Target Path
%th &nbsp;
%tbody
- @broadcast_messages.each do |message|
Loading
Loading
@@ -31,6 +32,8 @@
= message.starts_at
%td
= message.ends_at
%td
= message.target_path
%td
= link_to sprite_icon('pencil-square'), edit_admin_broadcast_message_path(message), title: 'Edit', class: 'btn'
= link_to sprite_icon('remove'), admin_broadcast_message_path(message), method: :delete, remote: true, title: 'Remove', class: 'js-remove-tr btn btn-danger'
Loading
Loading
- BroadcastMessage.current&.each do |message|
- current_broadcast_messages&.each do |message|
= broadcast_message(message)
---
title: Optimize query for CI pipelines of merge request
merge_request: 19653
author:
type: performance
---
title: Add path based targeting to broadcast messages
merge_request:
author:
type: added
Loading
Loading
@@ -11,15 +11,11 @@ class UsersNameLowerIndex < ActiveRecord::Migration[4.2]
disable_ddl_transaction!
 
def up
return unless Gitlab::Database.postgresql?
# On GitLab.com this produces an index with a size of roughly 60 MB.
execute "CREATE INDEX CONCURRENTLY #{INDEX_NAME} ON users (LOWER(name))"
end
 
def down
return unless Gitlab::Database.postgresql?
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME}"
end
end
Loading
Loading
@@ -18,7 +18,7 @@ class RescheduleCommitsCountForMergeRequestDiff < ActiveRecord::Migration[4.2]
def up
say 'Populating the MergeRequestDiff `commits_count` (reschedule)'
 
execute("SET statement_timeout TO '60s'") if Gitlab::Database.postgresql?
execute("SET statement_timeout TO '60s'")
 
MergeRequestDiff.where(commits_count: nil).each_batch(of: BATCH_SIZE) do |relation, index|
start_id, end_id = relation.pluck('MIN(id), MAX(id)').first
Loading
Loading
Loading
Loading
@@ -11,16 +11,12 @@ class ProjectNameLowerIndex < ActiveRecord::Migration[4.2]
disable_ddl_transaction!
 
def up
return unless Gitlab::Database.postgresql?
disable_statement_timeout do
execute "CREATE INDEX CONCURRENTLY #{INDEX_NAME} ON projects (LOWER(name))"
end
end
 
def down
return unless Gitlab::Database.postgresql?
disable_statement_timeout do
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME}"
end
Loading
Loading
Loading
Loading
@@ -5,34 +5,20 @@ class AddNotNullConstraintsToProjectAuthorizations < ActiveRecord::Migration[4.2
DOWNTIME = false
 
def up
if Gitlab::Database.postgresql?
# One-pass version for PostgreSQL
execute <<~SQL
execute <<~SQL
ALTER TABLE project_authorizations
ALTER COLUMN user_id SET NOT NULL,
ALTER COLUMN project_id SET NOT NULL,
ALTER COLUMN access_level SET NOT NULL
SQL
else
change_column_null :project_authorizations, :user_id, false
change_column_null :project_authorizations, :project_id, false
change_column_null :project_authorizations, :access_level, false
end
SQL
end
 
def down
if Gitlab::Database.postgresql?
# One-pass version for PostgreSQL
execute <<~SQL
execute <<~SQL
ALTER TABLE project_authorizations
ALTER COLUMN user_id DROP NOT NULL,
ALTER COLUMN project_id DROP NOT NULL,
ALTER COLUMN access_level DROP NOT NULL
SQL
else
change_column_null :project_authorizations, :user_id, true
change_column_null :project_authorizations, :project_id, true
change_column_null :project_authorizations, :access_level, true
end
SQL
end
end
Loading
Loading
@@ -464,15 +464,12 @@ class BackportEnterpriseSchema < ActiveRecord::Migration[5.0]
end
 
def update_environments
return unless Gitlab::Database.postgresql?
return if index_exists?(:environments, :name, name: 'index_environments_on_name_varchar_pattern_ops')
 
execute('CREATE INDEX CONCURRENTLY index_environments_on_name_varchar_pattern_ops ON environments (name varchar_pattern_ops);')
end
 
def revert_environments
return unless Gitlab::Database.postgresql?
remove_concurrent_index_by_name(
:environments,
'index_environments_on_name_varchar_pattern_ops'
Loading
Loading
# frozen_string_literal: true
class AddTargetPathToBroadcastMessage < ActiveRecord::Migration[5.2]
DOWNTIME = false
def change
add_column :broadcast_messages, :target_path, :string, limit: 255
end
end
Loading
Loading
@@ -27,8 +27,6 @@ class CompositePrimaryKeysMigration < ActiveRecord::Migration[4.2]
disable_ddl_transaction!
 
def up
return unless Gitlab::Database.postgresql?
disable_statement_timeout do
TABLES.each do |index|
add_primary_key(index)
Loading
Loading
@@ -37,8 +35,6 @@ class CompositePrimaryKeysMigration < ActiveRecord::Migration[4.2]
end
 
def down
return unless Gitlab::Database.postgresql?
disable_statement_timeout do
TABLES.each do |index|
remove_primary_key(index)
Loading
Loading
Loading
Loading
@@ -14,11 +14,9 @@ class RemovePermanentFromRedirectRoutes < ActiveRecord::Migration[4.2]
# These indexes were created on Postgres only in:
# ReworkRedirectRoutesIndexes:
# https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/16211
if Gitlab::Database.postgresql?
disable_statement_timeout do
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_PERM};"
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_TEMP};"
end
disable_statement_timeout do
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_PERM};"
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_TEMP};"
end
 
remove_column(:redirect_routes, :permanent)
Loading
Loading
@@ -27,11 +25,9 @@ class RemovePermanentFromRedirectRoutes < ActiveRecord::Migration[4.2]
def down
add_column(:redirect_routes, :permanent, :boolean)
 
if Gitlab::Database.postgresql?
disable_statement_timeout do
execute("CREATE INDEX CONCURRENTLY #{INDEX_NAME_PERM} ON redirect_routes (lower(path) varchar_pattern_ops) where (permanent);")
execute("CREATE INDEX CONCURRENTLY #{INDEX_NAME_TEMP} ON redirect_routes (lower(path) varchar_pattern_ops) where (not permanent or permanent is null) ;")
end
disable_statement_timeout do
execute("CREATE INDEX CONCURRENTLY #{INDEX_NAME_PERM} ON redirect_routes (lower(path) varchar_pattern_ops) where (permanent);")
execute("CREATE INDEX CONCURRENTLY #{INDEX_NAME_TEMP} ON redirect_routes (lower(path) varchar_pattern_ops) where (not permanent or permanent is null) ;")
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment