Commit 5595d737 authored by Rubén Dávila's avatar Rubén Dávila

Small refactor and fix for RuboCop

parent bd8e3606
...@@ -22,14 +22,11 @@ class GpgSignature < ActiveRecord::Base ...@@ -22,14 +22,11 @@ class GpgSignature < ActiveRecord::Base
validates :gpg_key_primary_keyid, presence: true validates :gpg_key_primary_keyid, presence: true
def self.with_key_and_subkeys(gpg_key) def self.with_key_and_subkeys(gpg_key)
return none unless gpg_key subkey_ids = gpg_key.subkeys.pluck(:id)
t = arel_table
subkey_ids = gpg_key&.subkeys&.pluck(:id)
where( where(
t[:gpg_key_id].eq(gpg_key&.id).or( arel_table[:gpg_key_id].eq(gpg_key.id).or(
t[:gpg_key_subkey_id].in(subkey_ids) arel_table[:gpg_key_subkey_id].in(subkey_ids)
) )
) )
end end
......
...@@ -8,11 +8,13 @@ class ScheduleCreateGpgKeySubkeysFromGpgKeys < ActiveRecord::Migration ...@@ -8,11 +8,13 @@ class ScheduleCreateGpgKeySubkeysFromGpgKeys < ActiveRecord::Migration
class GpgKey < ActiveRecord::Base class GpgKey < ActiveRecord::Base
self.table_name = 'gpg_keys' self.table_name = 'gpg_keys'
include EachBatch
end end
def up def up
GpgKey.select(:id).in_batches do |relation| GpgKey.select(:id).each_batch do |gpg_keys|
jobs = relation.pluck(:id).map do |id| jobs = gpg_keys.pluck(:id).map do |id|
['CreateGpgKeySubkeysFromGpgKeys', [id]] ['CreateGpgKeySubkeysFromGpgKeys', [id]]
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