Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip journal creation on import #888

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### New Features

* [#888](https://github.com/toptal/chewy/pull/888/files): Skip journal creation on import ([@konalegi](https://github.com/konalegi))

### Changes

### Bugs Fixed
Expand Down
2 changes: 1 addition & 1 deletion lib/chewy/index/import/routine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def initialize(index, **options)
# Creates the journal index and the corresponding index if necessary.
# @return [Object] whatever
def create_indexes!
Chewy::Stash::Journal.create if @options[:journal]
Chewy::Stash::Journal.create if @options[:journal] && !Chewy.configuration[:skip_journal_creation_on_import]
return if Chewy.configuration[:skip_index_creation_on_import]

@index.create!(**@bulk_options.slice(:suffix)) unless @index.exists?
Expand Down
13 changes: 13 additions & 0 deletions lib/chewy/rake_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,19 @@ def journal_clean(time: nil, only: nil, except: nil, delete_by_query_options: {}
end
end

# Creates journal index.
#
# @example
# Chewy::RakeHelper.journal_create # creates journal
#
# @param output [IO] output io for logging
# @return Chewy::Index Returns instance of chewy index
def journal_create(output: $stdout)
subscribed_task_stats(output) do
Chewy::Stash::Journal.create!
end
end

# Eager loads and returns all the indexes defined in the application
# except Chewy::Stash::Specification and Chewy::Stash::Journal.
#
Expand Down
5 changes: 5 additions & 0 deletions lib/tasks/chewy.rake
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ namespace :chewy do
end

namespace :journal do
desc 'Create manually journal, useful when `skip_journal_creation_on_import` is used'
task create: :environment do |_task, _args|
Chewy::RakeHelper.journal_create
end

desc 'Applies changes that were done after the specified time for the specified indexes/types or all of them'
task apply: :environment do |_task, args|
Chewy::RakeHelper.journal_apply(**parse_journal_args(args.extras))
Expand Down
13 changes: 13 additions & 0 deletions spec/chewy/index/import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ def subscribe_notification
CitiesIndex.import(dummy_city)
end
end

context 'skip journal creation on import' do
before do
Chewy::Stash::Journal.create!
Chewy.config.settings[:skip_journal_creation_on_import] = true
end
after { Chewy.config.settings[:skip_journal_creation_on_import] = nil }

specify do
expect(Chewy::Stash::Journal).not_to receive(:create!)
CitiesIndex.import(dummy_city, journal: true)
end
end
end

shared_examples 'importing' do
Expand Down
11 changes: 11 additions & 0 deletions spec/chewy/rake_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,17 @@
end
end

describe '.journal_create' do
specify do
output = StringIO.new
described_class.journal_create(output: output)
expect(Chewy::Stash::Journal.exists?).to be_truthy
expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
Total: \\d+s\\Z
OUTPUT
end
end

describe '.reindex' do
before do
journal
Expand Down