Commit f00cec60 authored by Shinya Maeda's avatar Shinya Maeda

Revert logic of calculating checksum

parent 99b0542c
......@@ -6,7 +6,6 @@ module Ci
belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id
before_save :set_size, if: :file_changed?
before_save :set_checksum, if: :file_changed?
mount_uploader :file, JobArtifactUploader
......@@ -26,10 +25,6 @@ module Ci
self.size = file.size
end
def set_checksum
self.checksum = file.checksum
end
def expire_in
expire_at - Time.now if expire_at
end
......
......@@ -71,14 +71,6 @@ class GitlabUploader < CarrierWave::Uploader::Base
!!model
end
##
# ObjectStorage::Concern extends this method for remote files
def use_file
if file_storage?
return yield path
end
end
private
# Designed to be overridden by child uploaders that have a dynamic path
......
......@@ -9,12 +9,6 @@ class JobArtifactUploader < GitlabUploader
model.size
end
def checksum
return calc_checksum if model.checksum.nil?
model.checksum
end
def store_dir
dynamic_segment
end
......@@ -27,12 +21,6 @@ class JobArtifactUploader < GitlabUploader
private
def calc_checksum
use_file do |file_path|
return Digest::SHA256.file(file_path).hexdigest
end
end
def dynamic_segment
creation_date = model.created_at.utc.strftime('%Y_%m_%d')
......
......@@ -104,5 +104,3 @@
- update_user_activity
- upload_checksum
- web_hook
- object_storage:update_artifact_checksum_worker
\ No newline at end of file
# Concern for setting Sidekiq settings for the various GitLab ObjectStorage workers.
module ObjectStorageQueue
extend ActiveSupport::Concern
included do
queue_namespace :object_storage
end
end
class UpdateArtifactChecksumWorker
include ApplicationWorker
include ObjectStorageQueue
def perform(job_artifact_id)
Ci::JobArtifact.find_by(id: job_artifact_id).try do |job_artifact|
job_artifact.set_checksum
job_artifact.save!
end
end
end
class UpdateChecksumForCiJobArtifacts < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
BATCH_SIZE = 2500
class JobArtifact < ActiveRecord::Base
include EachBatch
self.table_name = 'ci_job_artifacts'
end
def up
UpdateChecksumForCiJobArtifacts::JobArtifact
.where('checksum IS NULL')
.each_batch(of: BATCH_SIZE) do |relation|
ids = relation.pluck(:id).map { |id| [id] }
UpdateArtifactChecksumWorker.bulk_perform_async(ids)
end
end
def down
# no-op
end
end
require 'spec_helper'
describe ObjectStorageQueue do
let(:worker) do
Class.new do
def self.name
'DummyWorker'
end
include ApplicationWorker
include ObjectStorageQueue
end
end
it 'sets a default object storage queue automatically' do
expect(worker.sidekiq_options['queue'])
.to eq 'object_storage:dummy'
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment