2010-04-20 23:05:11 +00:00
|
|
|
def get_metatags(tags)
|
2014-08-23 19:42:17 +09:00
|
|
|
metatags, _tags = tags.scan(/\S+/).partition { |x| x =~ /^(?:rating):/ }
|
2010-04-20 23:05:11 +00:00
|
|
|
ret = {}
|
|
|
|
metatags.each do |metatag|
|
|
|
|
case metatag
|
|
|
|
when /^rating:([qse])/
|
2014-08-23 17:54:43 +09:00
|
|
|
ret[:rating] ||= Regexp.last_match[1]
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-23 16:56:00 +09:00
|
|
|
ret
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
namespace :posts do
|
2014-08-23 16:16:09 +09:00
|
|
|
desc "Recalculate all post votes"
|
2010-04-20 23:05:11 +00:00
|
|
|
task :recalc_votes => :environment do
|
|
|
|
Post.recalculate_score
|
|
|
|
end
|
|
|
|
|
2014-08-23 16:16:09 +09:00
|
|
|
desc "Set missing CRC32s"
|
2010-04-20 23:05:11 +00:00
|
|
|
task :set_crc32 => :environment do
|
|
|
|
Post.find(:all, :order => "ID ASC", :conditions => "crc32 IS NULL OR (sample_width IS NOT NULL AND sample_crc32 IS NULL)").each do |post|
|
|
|
|
p "Post #{post.id}..."
|
|
|
|
old_md5 = post.md5
|
|
|
|
|
|
|
|
# Older deleted posts will have been deleted from disk. Tolerate the error from this;
|
|
|
|
# just leave the CRCs null.
|
|
|
|
begin
|
|
|
|
post.regenerate_hash
|
|
|
|
post.generate_sample_hash
|
2014-08-23 19:42:17 +09:00
|
|
|
rescue SocketError, URI::Error, Timeout::Error, SystemCallError
|
2010-04-20 23:05:11 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
if old_md5 != post.md5
|
|
|
|
# Changing the MD5 would break the file path, and we only care about populating
|
|
|
|
# CRC32.
|
|
|
|
p "warning: post #{post.id} MD5 is incorrect; got #{post.md5}, expected #{old_md5} (corrupted file?)"
|
|
|
|
end
|
|
|
|
post.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-23 16:16:09 +09:00
|
|
|
desc "Add missing tag history data"
|
2010-04-20 23:05:11 +00:00
|
|
|
task :add_post_history => :environment do
|
|
|
|
# Add missing metatags to post_tag_history, using the nearest data (nearby tag
|
|
|
|
# history or the post itself). We won't break if this is missing, but this data
|
|
|
|
# will be added on the next change for every post, which will make it look like
|
|
|
|
# people are making changes that they're not.
|
|
|
|
PostTagHistory.transaction do
|
|
|
|
PostTagHistory.find(:all, :order => "id ASC").each do |change|
|
2014-08-23 20:18:26 +09:00
|
|
|
#:all, :order => "id ASC").each
|
2010-04-20 23:05:11 +00:00
|
|
|
post = Post.find(change.post_id)
|
|
|
|
next_change = change.next
|
|
|
|
if next_change
|
|
|
|
next_change = next_change.tags
|
|
|
|
else
|
|
|
|
next_change = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
prev_change = change.previous
|
|
|
|
if prev_change
|
|
|
|
prev_change = prev_change.tags
|
|
|
|
else
|
|
|
|
prev_change = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
sources = [prev_change, next_change, post.cached_tags_versioned].map { |x| get_metatags(x) }
|
|
|
|
current_metatags = get_metatags(change.tags)
|
|
|
|
|
|
|
|
metatags_to_add = []
|
|
|
|
[:rating].each do |metatag|
|
|
|
|
next if current_metatags[metatag]
|
|
|
|
val = nil
|
|
|
|
sources.each { |source| val ||= source[metatag] }
|
|
|
|
|
|
|
|
metatags_to_add += [metatag.to_s + ":" + val]
|
|
|
|
end
|
|
|
|
|
|
|
|
next if metatags_to_add.empty?
|
|
|
|
change.tags = (metatags_to_add + [change.tags]).join(" ")
|
|
|
|
change.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-23 16:16:09 +09:00
|
|
|
desc "Upload posts to mirrors"
|
2010-04-20 23:05:11 +00:00
|
|
|
task :mirror => :environment do
|
2014-08-23 18:10:14 +09:00
|
|
|
Post.find(:all, :conditions => ["NOT is_warehoused AND status <> 'deleted'"], :order => "id DESC").each do |post|
|
2010-04-20 23:05:11 +00:00
|
|
|
p "Mirroring ##{post.id}..."
|
|
|
|
post.upload_to_mirrors
|
2014-08-23 18:10:14 +09:00
|
|
|
end
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|
2010-09-03 22:57:44 +00:00
|
|
|
|
2014-08-23 16:16:09 +09:00
|
|
|
desc "Recalculate pool post counts"
|
2010-09-03 22:57:44 +00:00
|
|
|
task :recalc_pools => :environment do
|
2014-08-23 18:10:14 +09:00
|
|
|
Pool.find(:all).each do |pool|
|
2010-09-03 22:57:44 +00:00
|
|
|
pool.recalculate_post_count
|
|
|
|
pool.save!
|
2014-08-23 18:10:14 +09:00
|
|
|
end
|
2010-09-03 22:57:44 +00:00
|
|
|
end
|
2010-11-15 14:02:17 +00:00
|
|
|
|
2014-08-23 16:16:09 +09:00
|
|
|
desc "Regenerate post previews"
|
2010-11-15 14:02:17 +00:00
|
|
|
task :regen_previews => :environment do
|
2010-11-15 14:10:22 +00:00
|
|
|
ActiveRecord::Base.select_values_sql("SELECT p.id FROM posts p ORDER BY p.id DESC").each do |post_id|
|
|
|
|
p "%i..." % post_id
|
|
|
|
post = Post.find_by_id(post_id)
|
2010-11-15 14:02:17 +00:00
|
|
|
post.regenerate_images(:preview, :force_regen => false)
|
|
|
|
post.save!
|
|
|
|
end
|
|
|
|
end
|
2011-01-17 02:17:53 +00:00
|
|
|
|
2014-08-23 16:16:09 +09:00
|
|
|
desc "Regenerate JPEG CRCs"
|
2011-01-17 02:17:53 +00:00
|
|
|
task :regen_jpeg_crcs => :environment do
|
|
|
|
ActiveRecord::Base.select_values_sql("SELECT p.id FROM posts p ORDER BY p.id DESC").each do |post_id|
|
|
|
|
p "%i..." % post_id
|
|
|
|
post = Post.find_by_id(post_id)
|
2014-11-08 22:57:37 +09:00
|
|
|
if post.regenerate_jpeg_hash
|
2011-01-17 02:17:53 +00:00
|
|
|
post.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|