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

Only apply journal for current index when resetting #434

Merged
merged 2 commits into from
Oct 7, 2016
Merged

Only apply journal for current index when resetting #434

merged 2 commits into from
Oct 7, 2016

Conversation

fpbouchard
Copy link

When resetting an index that has journaling, the current code actually replays all the journal entries, no matter which index has just been reset.

This PR only applies journal entries for the given index. I find my code a bit clunky (the new query method).

Any thoughts?

@pyromaniac
Copy link
Contributor

Hey, awesome patch, will review it soon, thanks!

@@ -48,15 +48,19 @@ def any_records?
@records.any?
end

def apply_changes_from(time)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm not sure this interface makes sense, it will be never used, we are using the journal instance only for filling it in now.

private

def identify(objects)
@index.adapter.identify(objects)
end

class << self
def apply_changes_from(time)
group(entries_from(time)).each do |entry|
def apply_changes_from(time, options = {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to support multiple indexes passing?

comparator => time.to_i
def query(time, comparator, index = nil, use_filter = true)
filter_query =
if use_filter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it makes sense to move some logic to separate methods? as for me, there are too many if-else statements in this method. Also, I would move this part to a separate method instead of just assigning it to filter_query

expect(CountryIndex.all.to_a.length).to eq 1

# Replay on specific index
Chewy::Journal.new(CityIndex).apply_changes_from(time)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I would change the interface, to not pass an index name to the journal instance. I think it doesn't make sense. I would just pass it as :only parameter toapply_changes_from class method. Like there: Chewy::Journal.apply_changes_from(time, only: [CityIndex])

@fpbouchard
Copy link
Author

Updated it, let me know what you guys think.

@pyromaniac pyromaniac merged commit 62d4cfb into toptal:master Oct 7, 2016
@pyromaniac
Copy link
Contributor

pyromaniac commented Oct 7, 2016

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants