app/models/page.rb
# TODO: abstract this to allow updates of the other count fields.
# NOTE: This isn't as hairy as it looks. Currently (July 2018) takes under 10 minutes.
abstract this to allow updates of the other count fields.
NOTE: This isn't as hairy as it looks. Currently (July 2018) takes under 10 minutes.
abstract this to allow updates of the other count fields . NOTE : This isn ' t as hairy as it looks . Currently ( July 2018 ) takes under 10 minutes .
def fix_media_counts
      pids = PageContent.connection.execute('select DISTINCT(page_id) from page_contents where content_type = "Medium"')
      pids.each do |page_id|
        count = PageContent.where(page_id: page_id, content_type: 'Medium').count
        Page.where(id: page_id).update_all(media_count: count)
      end
    end
def fix_media_counts pids = PageContent . connection . execute ( 'select DISTINCT(page_id) from page_contents where content_type = "Medium"' ) pids . each do | page_id | count = PageContent . where ( page_id : page_id , content_type : 'Medium' ) . count Page . where ( id : page_id ) . update_all ( media_count : count ) end end
TODO: abstract this to allow updates of the other count fields.
TODO : abstract this to allow updates of the other count fields .
# NOTE: Skipping loading any models; this just calls the DB, even though it looks weird to "update_all" one row.