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

DB Migration chokes deployment #4924

Closed
icarito opened this issue Mar 6, 2019 · 11 comments
Closed

DB Migration chokes deployment #4924

icarito opened this issue Mar 6, 2019 · 11 comments

Comments

@icarito
Copy link
Member

icarito commented Mar 6, 2019

This migration appears stuck in production deployment process:

class AddFirstTagPoster < ActiveRecord::Migration[5.1]
  def find_and_update
    User.joins(:node).where('node.status = ?', 1).each do |user|
      if user.nodes.present?
        node = user.nodes.first
        node.add_tag('first-time-post', user)
      end
    end
  end

  def up
    find_and_update
  end
end
@icarito
Copy link
Member Author

icarito commented Mar 6, 2019

My impression is that joining Users and Node is heavy...

@jywarren
Copy link
Member

jywarren commented Mar 6, 2019 via email

@namangupta01
Copy link
Member

What exactly we want to do here?

@jywarren
Copy link
Member

jywarren commented Mar 6, 2019

I think we need to add additional conditions to the User...() call so that we aren't trying to fetch all user records. But according to previous tests, this should only be calling 7k records, which isn't all that much:

> User.joins(:node).where('node.status = ?', 1).count
=> 7278
> User.joins(:comments).count
=> 15201

@icarito do you think even 7k records would be too many and could be causing this?

@jywarren
Copy link
Member

jywarren commented Mar 6, 2019

Testing the above on live db console to benchmark...

@jywarren
Copy link
Member

jywarren commented Mar 6, 2019

I wonder if it's just taking a really long time to go through and make all the tags, but that potentially it's not actually hanging but just taking a really long time to iterate through 7k records and do this for each one?

@jywarren
Copy link
Member

jywarren commented Mar 7, 2019

OK, compare:

> User.joins(:node).where('node.status = ?', 1).count => 7278

User.joins(:node).where('node.status = ?', 1).distinct.count => 1407

User.includes(:node).where(node: { status: 1 }).count => 1407

Gah, ok well that helps a bit...

@jywarren
Copy link
Member

jywarren commented Mar 7, 2019

Attempted fix here: 1737876

@jywarren
Copy link
Member

jywarren commented Mar 7, 2019

Deploying this now... hoping!

@jywarren
Copy link
Member

jywarren commented Mar 7, 2019

Done! It worked!

@jywarren jywarren closed this as completed Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants