Skip to content

Commit

Permalink
remove fix_* tasks as we ensured we won't need them anymore a long ti…
Browse files Browse the repository at this point in the history
…me ago
  • Loading branch information
nilsding committed Jul 9, 2022
1 parent 31e9d7a commit 4f1260b
Showing 1 changed file with 1 addition and 150 deletions.
151 changes: 1 addition & 150 deletions Rakefile
Expand Up @@ -228,160 +228,11 @@ namespace :justask do
puts "Removed #{removed} users"
end

desc "Subscribes everyone to their answers"
task fix_submarines: :environment do
format = '%t (%c/%C) [%b>%i] %e'

total = Answer.count
progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total
subscribed = 0

Answer.all.each do |a|
if not a.user.nil?
Subscription.subscribe a.user, a
subscribed += 1
end

progress.increment
end

puts "Subscribed to #{subscribed} posts."
end

desc "Destroy lost subscriptions"
task fix_torpedoes: :environment do
format = '%t (%c/%C) [%b>%i] %e'

total = Subscription.count
progress = ProgressBar.create title: 'Processing subscriptions', format: format, starting_at: 0, total: total
destroyed = 0
Subscription.all.each do |s|
if s.user.nil? or s.answer.nil?
s.destroy
destroyed += 1
end

progress.increment
end

puts "Put #{destroyed} subscriptions up for adoption."
end

desc "Fixes reports"
task fix_reports: :environment do
format = '%t (%c/%C) [%b>%i] %e'

total = Report.count
progress = ProgressBar.create title: 'Processing reports', format: format, starting_at: 0, total: total
destroyed = 0
Report.all.each do |r|
if r.target.nil? and not r.deleted?
r.deleted = true
r.save
destroyed += 1
elsif r.user.nil?
r.destroy
destroyed += 1
end
progress.increment
end

puts "Marked #{destroyed} reports as deleted."
end

desc "Fixes everything else"
task fix_db: :environment do
format = '%t (%c/%C) [%b>%i] %e'
destroyed_count = {
inbox: 0,
question: 0,
answer: 0,
smile: 0,
comment: 0,
subscription: 0,
report: 0
}

total = Inbox.count
progress = ProgressBar.create title: 'Processing inboxes', format: format, starting_at: 0, total: total
Inbox.all.each do |n|
if n.question.nil?
n.destroy
destroyed_count[:inbox] += 1
end
progress.increment
end

total = Question.count
progress = ProgressBar.create title: 'Processing questions', format: format, starting_at: 0, total: total
Question.all.each do |q|
if q.user.nil?
q.user_id = nil
q.author_is_anonymous = true
destroyed_count[:question] += 1
end
progress.increment
end

total = Answer.count
progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total
Answer.all.each do |a|
if a.user.nil? or a.question.nil?
a.destroy
destroyed_count[:answer] += 1
end
progress.increment
end

total = Comment.count
progress = ProgressBar.create title: 'Processing comments', format: format, starting_at: 0, total: total
Comment.all.each do |c|
if c.user.nil? or c.answer.nil?
c.destroy
destroyed_count[:comment] += 1
end
progress.increment
end

total = Subscription.count
progress = ProgressBar.create title: 'Processing subscriptions', format: format, starting_at: 0, total: total
Subscription.all.each do |s|
if s.user.nil? or s.answer.nil?
s.destroy
destroyed_count[:subscription] += 1
end

progress.increment
end

total = Report.count
progress = ProgressBar.create title: 'Processing reports', format: format, starting_at: 0, total: total
Report.all.each do |r|
if r.target.nil? and not r.deleted?
r.deleted = true
r.save
destroyed_count[:report] += 1
elsif r.user.nil?
r.destroy
destroyed_count[:report] += 1
end
progress.increment
end

puts "Put #{destroyed_count[:subscription]} subscriptions up for adoption."
puts "Purged #{destroyed_count[:inbox]} dead inbox entries."
puts "Marked #{destroyed_count[:question]} questions as anonymous."
puts "Purged #{destroyed_count[:answer]} dead answers."
puts "Purged #{destroyed_count[:comment]} dead comments."
puts "Purged #{destroyed_count[:subscription]} dead subscriptions."
puts "Marked #{destroyed_count[:report]} reports as deleted."
end

desc "Prints lonely people."
task loners: :environment do
people = {}
Question.all.each do |q|
if q.author_is_anonymous and q.author_name != 'justask'
if q.author_is_anonymous && !%w[justask retrospring_exporter].include?(q.author_identifier)
q.answers.each do |a|
if q.user == a.user
people[q.user.screen_name] ||= 0
Expand Down

0 comments on commit 4f1260b

Please sign in to comment.