app/models/page.rb
# NOTE: you prrrrrrobaby want to fix_media_counts before you call this.
you prrrrrrobaby want to fix_media_counts before you call this.
you prrrrrrobaby want to fix_media_counts before you call this .
def fix_missing_icons
      fix_zombie_icons
      pages = []
      Page.where(medium_id: nil).where('media_count > 0').find_each do |page|
        page.medium_id = page.media.first&.id
        pages << page
        if pages.size > 999 
          Page.import!(pages, on_duplicate_key_update: [:medium_id])
          pages = []
        end
      end
      Page.import!(pages, on_duplicate_key_update: [:medium_id]) unless pages.empty?
    end
def fix_missing_icons fix_zombie_icons pages = [ ] Page . where ( medium_id : nil ) . where ( 'media_count > 0' ) . find_each do | page | page . medium_id = page . media . first &. id pages << page if pages . size > 999 Page . import! ( pages , on_duplicate_key_update : [ :medium_id ] ) pages = [ ] end end Page . import! ( pages , on_duplicate_key_update : [ :medium_id ] ) unless pages . empty? end
NOTE: you prrrrrrobaby want to fix_media_counts before you call this.
NOTE : you prrrrrrobaby want to fix_media_counts before you call this .
# There's no NICE way to include the media, so this, yes, will make a query for every page. We don't run this # method often enough to warrant speeding it up. # FLUSH!