script/embeddable_stats.rb
# Another version of the same script, but it iterates directly over selected class. If there only a few instances
# this might be faster approach.
Another version of the same script, but it iterates directly over selected class. If there only a few instances
this might be faster approach.
Another version of the same script but it iterates directly over selected class . If there only a few instances this might be faster approach .
def print_embeddable_stats2(embeddable_type, host = "authoring.concord.org")
  ActiveRecord::Base.logger = nil 
  stats = {}
  count = 0
  embeddable_type.classify.safe_constantize.find_each do |lb|
    count += 1
    if count % 1000 == 0
      print "." 
    end
    activity = lb.page && lb.page.lightweight_activity
    if activity
      url = Rails.application.routes.url_helpers.activity_url(activity, host: host)
      unless stats[activity.name]
        runs = activity.runs
        stats[activity.name] = {
          act_name: activity.name,
          act_id: activity.id,
          act_url: url,
          runs_count: runs.count,
          last_run: runs.count > 0 ? activity.runs.order(:updated_at).last.updated_at : "never",
          embeddable_count: 1
        }
      else
        stats[activity.name][:embeddable_count] += 1
      end
    end
  end
  puts 
  puts "activity name\tactivity id\tactivity url\truns count\tlast run\t#{embeddable_type} count"
  stats.each do |key, s|
    puts "#{s[:act_name]}\t#{s[:act_id]}\t#{s[:act_url]}\t#{s[:runs_count]}\t#{s[:last_run]}\t#{s[:embeddable_count]}"
  end
  nil
end
def print_embeddable_stats2 ( embeddable_type , host = "authoring.concord.org" ) ActiveRecord :: Base . logger = nil stats = { } count = 0 embeddable_type . classify . safe_constantize . find_each do | lb | count += 1 if count % 1000 == 0 print "." end activity = lb . page && lb . page . lightweight_activity if activity url = Rails . application . routes . url_helpers . activity_url ( activity , host : host ) unless stats [ activity . name ] runs = activity . runs stats [ activity . name ] = { act_name : activity . name , act_id : activity . id , act_url : url , runs_count : runs . count , last_run : runs . count > 0 ? activity . runs . order ( :updated_at ) . last . updated_at : "never" , embeddable_count : 1 } else stats [ activity . name ] [ :embeddable_count ] += 1 end end end puts puts "activity name\tactivity id\tactivity url\truns count\tlast run\t#{embeddable_type} count" stats . each do | key , s | puts "#{s[:act_name]}\t#{s[:act_id]}\t#{s[:act_url]}\t#{s[:runs_count]}\t#{s[:last_run]}\t#{s[:embeddable_count]}" end nil end
Another version of the same script, but it iterates directly over selected class.
Another version of the same script but it iterates directly over selected class .
# disable SQL logging # print something to see some progress # new line after last .
embeddable_type
<not_specific>
host
<not_specific>