Skip to content

Commit

Permalink
feature: specify intialization batch_size as field parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dsalahutdinov committed Oct 22, 2017
1 parent f9173a1 commit a5a9c32
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 42 deletions.
8 changes: 4 additions & 4 deletions lib/treasury/fields/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ class Base
include ActiveSupport::Callbacks
extend Apress::Sources::Accessors

DEFAULT_BATCH_SIZE = 1000

# пауза после обработки батча данных
# позволяет снизить нагрузку на БД при инициализации,
# за счет увеличения времени инициализации
Expand All @@ -21,6 +19,8 @@ class Base
class_attribute :_instance

class_attribute :initialize_method
class_attribute :default_batch_size
self.default_batch_size = 1000

self.initialize_method = :offset

Expand Down Expand Up @@ -69,7 +69,7 @@ def initialize(field_model)
end

def init_params
@batch_size = DEFAULT_BATCH_SIZE
@batch_size = field_params.fetch(:batch_size, self.class.default_batch_size)
@batch_pause = DEFAULT_BATCH_PAUSE
end

Expand Down Expand Up @@ -543,7 +543,7 @@ def cached_state
# Returns Hash.

def field_params
field_model.params.with_indifferent_access || {}
(field_model.params || {}).with_indifferent_access
end

# Private: Возвращает префикс хранения для полей.
Expand Down
13 changes: 1 addition & 12 deletions lib/treasury/fields/company/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@ class Base < Treasury::Fields::Base

extract_attribute_name :company

BATCH_SIZE = 10_000

protected

# Protected: Инициализирует параметры поля.
#
# Returns nothing.

def init_params
super
self.batch_size = BATCH_SIZE
end
self.default_batch_size = 10_000
end
end
end
Expand Down
13 changes: 1 addition & 12 deletions lib/treasury/fields/product/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@ class Base < Treasury::Fields::Base

extract_attribute_name :product

BATCH_SIZE = 50_000

protected

# Protected: Инициализирует параметры поля.
#
# Returns nothing.

def init_params
super
self.batch_size = BATCH_SIZE
end
self.default_batch_size = 50_000
end
end
end
Expand Down
13 changes: 1 addition & 12 deletions lib/treasury/fields/user/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@ class Base < Treasury::Fields::Base

extract_attribute_name :user

BATCH_SIZE = 25_000

protected

# Protected: Инициализирует параметры поля.
#
# Returns nothing.

def init_params
super
self.batch_size = BATCH_SIZE
end
self.default_batch_size = 25_000
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/treasury/fields/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.value_as_integer(params)
end

describe TreasuryFieldsBase do
subject { described_class.new(nil) }
subject { described_class.new(build_stubbed(:'denormalization/field')) }

context '#data_changed' do
let(:chaged_objects) { [1, 2, 3] }
Expand Down
2 changes: 1 addition & 1 deletion treasury.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'oj', '>= 2.9.9'

spec.add_development_dependency 'rspec-rails'
spec.add_development_dependency 'factory_girl_rails'
spec.add_development_dependency 'factory_girl_rails', '<= 4.8.0'
spec.add_development_dependency 'apress-rspec'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'combustion', '>= 0.5.3'
Expand Down

0 comments on commit a5a9c32

Please sign in to comment.