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
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/ci/build_trace_chunk.rb')
-rw-r--r--app/models/ci/build_trace_chunk.rb41
1 files changed, 26 insertions, 15 deletions
diff --git a/app/models/ci/build_trace_chunk.rb b/app/models/ci/build_trace_chunk.rb
index ee999a3395d..bdba9e6ed3c 100644
--- a/app/models/ci/build_trace_chunk.rb
+++ b/app/models/ci/build_trace_chunk.rb
@@ -1,12 +1,12 @@
module Ci
class BuildTraceChunk < ActiveRecord::Base
+ include FastDestroyAll
extend Gitlab::Ci::Model
belongs_to :build, class_name: "Ci::Build", foreign_key: :build_id
- after_destroy :redis_delete_data, if: :redis?
-
default_value_for :data_store, :redis
+ fast_destroy_all_with :redis_delete_data, :redis_data_keys
WriteError = Class.new(StandardError)
@@ -21,6 +21,26 @@ module Ci
db: 2
}
+ class << self
+ def redis_data_key(build_id, chunk_index)
+ "gitlab:ci:trace:#{build_id}:chunks:#{chunk_index}"
+ end
+
+ def redis_data_keys
+ redis.pluck(:build_id, :chunk_index).map do |data|
+ redis_data_key(data.first, data.second)
+ end
+ end
+
+ def redis_delete_data(keys)
+ return if keys.empty?
+
+ Gitlab::Redis::SharedState.with do |redis|
+ redis.del(keys)
+ end
+ end
+ end
+
##
# Data is memoized for optimizing #size and #end_offset
def data
@@ -60,7 +80,8 @@ module Ci
break unless size > 0
self.update!(raw_data: data, data_store: :db)
- redis_delete_data
+ key = self.class.redis_data_key(build_id, chunk_index)
+ self.class.redis_delete_data([key])
end
end
@@ -108,26 +129,16 @@ module Ci
def redis_data
Gitlab::Redis::SharedState.with do |redis|
- redis.get(redis_data_key)
+ redis.get(self.class.redis_data_key(build_id, chunk_index))
end
end
def redis_set_data(data)
Gitlab::Redis::SharedState.with do |redis|
- redis.set(redis_data_key, data, ex: CHUNK_REDIS_TTL)
- end
- end
-
- def redis_delete_data
- Gitlab::Redis::SharedState.with do |redis|
- redis.del(redis_data_key)
+ redis.set(self.class.redis_data_key(build_id, chunk_index), data, ex: CHUNK_REDIS_TTL)
end
end
- def redis_data_key
- "gitlab:ci:trace:#{build_id}:chunks:#{chunk_index}"
- end
-
def redis_lock_key
"trace_write:#{build_id}:chunks:#{chunk_index}"
end