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/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-07 00:07:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-07 00:07:43 +0300
commit015663b70f1bcdae4483e38c2beac884f92da5b8 (patch)
tree6dd5a59c7f9a27c3cca22801ca30bf3dd8f9b401 /lib
parent5eb11b697d7ee280b0b5c2ff9a1850a3b5e9b7e3 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/database/migration_helpers.rb12
-rw-r--r--lib/sentry/client.rb15
-rw-r--r--lib/sentry/client/issue.rb4
-rw-r--r--lib/tasks/pngquant.rake97
4 files changed, 124 insertions, 4 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index f9340b262e5..1f246620a9c 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -158,7 +158,7 @@ module Gitlab
# name - The name of the foreign key.
#
# rubocop:disable Gitlab/RailsLogger
- def add_concurrent_foreign_key(source, target, column:, on_delete: :cascade, name: nil)
+ def add_concurrent_foreign_key(source, target, column:, on_delete: :cascade, name: nil, validate: true)
# Transactions would result in ALTER TABLE locks being held for the
# duration of the transaction, defeating the purpose of this method.
if transaction_open?
@@ -197,10 +197,16 @@ module Gitlab
# Validate the existing constraint. This can potentially take a very
# long time to complete, but fortunately does not lock the source table
# while running.
+ # Disable this check by passing `validate: false` to the method call
+ # The check will be enforced for new data (inserts) coming in,
+ # but validating existing data is delayed.
#
# Note this is a no-op in case the constraint is VALID already
- disable_statement_timeout do
- execute("ALTER TABLE #{source} VALIDATE CONSTRAINT #{options[:name]};")
+
+ if validate
+ disable_statement_timeout do
+ execute("ALTER TABLE #{source} VALIDATE CONSTRAINT #{options[:name]};")
+ end
end
end
# rubocop:enable Gitlab/RailsLogger
diff --git a/lib/sentry/client.rb b/lib/sentry/client.rb
index 65bedbf9e0f..211c828ccc3 100644
--- a/lib/sentry/client.rb
+++ b/lib/sentry/client.rb
@@ -71,9 +71,22 @@ module Sentry
end
def http_get(url, params = {})
- response = handle_request_exceptions do
+ http_request do
Gitlab::HTTP.get(url, **request_params.merge(params))
end
+ end
+
+ def http_put(url, params = {})
+ http_request do
+ Gitlab::HTTP.put(url, **request_params.merge({ body: params }))
+ end
+ end
+
+ def http_request
+ response = handle_request_exceptions do
+ yield
+ end
+
handle_response(response)
end
diff --git a/lib/sentry/client/issue.rb b/lib/sentry/client/issue.rb
index 28e87ab18a1..4a11c87faa4 100644
--- a/lib/sentry/client/issue.rb
+++ b/lib/sentry/client/issue.rb
@@ -15,6 +15,10 @@ module Sentry
http_get(issue_api_url(issue_id))[:body]
end
+ def update_issue(issue_id:, params:)
+ http_put(issue_api_url(issue_id), params)[:body]
+ end
+
def issue_api_url(issue_id)
issue_url = URI(url)
issue_url.path = "/api/0/issues/#{CGI.escape(issue_id.to_s)}/"
diff --git a/lib/tasks/pngquant.rake b/lib/tasks/pngquant.rake
new file mode 100644
index 00000000000..0197cc9dbcf
--- /dev/null
+++ b/lib/tasks/pngquant.rake
@@ -0,0 +1,97 @@
+return if Rails.env.production?
+
+require 'png_quantizator'
+require 'parallel'
+
+# The amount of variance (in bytes) allowed in
+# file size when testing for compression size
+TOLERANCE = 10
+
+namespace :pngquant do
+ # Returns an array of all images eligible for compression
+ def doc_images
+ Dir.glob('doc/**/*.png', File::FNM_CASEFOLD)
+ end
+
+ # Runs pngquant on an image and optionally
+ # writes the result to disk
+ def compress_image(file, overwrite_original)
+ compressed_file = "#{file}.compressed"
+ FileUtils.copy(file, compressed_file)
+
+ pngquant_file = PngQuantizator::Image.new(compressed_file)
+
+ # Run the image repeatedly through pngquant until
+ # the change in file size is within TOLERANCE
+ loop do
+ before = File.size(compressed_file)
+ pngquant_file.quantize!
+ after = File.size(compressed_file)
+ break if before - after <= TOLERANCE
+ end
+
+ savings = File.size(file) - File.size(compressed_file)
+ is_uncompressed = savings > TOLERANCE
+
+ if is_uncompressed && overwrite_original
+ FileUtils.copy(compressed_file, file)
+ end
+
+ FileUtils.remove(compressed_file)
+
+ [is_uncompressed, savings]
+ end
+
+ # Ensures pngquant is available and prints an error if not
+ def check_executable
+ unless system('pngquant --version', out: File::NULL)
+ warn(
+ 'Error: pngquant executable was not detected in the system.'.color(:red),
+ 'Download pngquant at https://pngquant.org/ and place the executable in /usr/local/bin'.color(:green)
+ )
+ abort
+ end
+ end
+
+ desc 'GitLab | pngquant | Compress all documentation PNG images using pngquant'
+ task :compress do
+ check_executable
+
+ files = doc_images
+ puts "Compressing #{files.size} PNG files in doc/**"
+
+ Parallel.each(files) do |file|
+ was_uncompressed, savings = compress_image(file, true)
+
+ if was_uncompressed
+ puts "#{file} was reduced by #{savings} bytes"
+ end
+ end
+ end
+
+ desc 'GitLab | pngquant | Checks that all documentation PNG images have been compressed with pngquant'
+ task :lint do
+ check_executable
+
+ files = doc_images
+ puts "Checking #{files.size} PNG files in doc/**"
+
+ uncompressed_files = Parallel.map(files) do |file|
+ is_uncompressed, _ = compress_image(file, false)
+ if is_uncompressed
+ puts "Uncompressed file detected: ".color(:red) + file
+ file
+ end
+ end.compact
+
+ if uncompressed_files.empty?
+ puts "All documentation images are optimally compressed!".color(:green)
+ else
+ warn(
+ "The #{uncompressed_files.size} image(s) above have not been optimally compressed using pngquant.".color(:red),
+ 'Please run "bin/rake pngquant:compress" and commit the result.'
+ )
+ abort
+ end
+ end
+end