Skip to content

Instantly share code, notes, and snippets.

@sclinede
Last active August 29, 2015 14:03
Show Gist options
  • Save sclinede/24b304b89dccbce58057 to your computer and use it in GitHub Desktop.
Save sclinede/24b304b89dccbce58057 to your computer and use it in GitHub Desktop.
def reload_companies_products(*ids)
Company.find(ids).each do |company|
company.products.find_each { |prod| prod.transmitter_update }
CompaniesSweeper.expire(company)
end
end
select id, ABS((id - 3)/7 - sphinx_internal_id) > 16 as cid from product_rt where company_id = 12690030 order by cid asc limit 307;
Company.find(<id>).tap { |c| c.products.find_each { |prod| prod.transmitter_update }; CompaniesSweeper.expire(c); }
@folklore
Copy link

def reload_companies_products(*ids)
  Company.select(:id).find(ids).each do |company|
    company.products.select(:id).find_each { |prod| prod.transmitter_update }
    CompaniesSweeper.expire(company)
    sleep 1
  end
end

companies_ids = Company.where('packet <> 0').pluck(:id) + [478534, 264, 87618, 306305, 110816, 396525, 64414, 319345, 392023, 140310]

reload_companies_products(companies_ids)

@folklore
Copy link

require 'timeout'

min_id = 3130000
max_id = 3141000
bad_product_ids = []

Product.select(:id).where("id <= ?", max_id).find_each(start: min_id) do |product|
  begin
    Timeout::timeout(2) { product.transmitter_update }
  rescue Timeout::Error
    bad_product_ids << product.id
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment