rubyruy (owner)

Revisions

gist: 220746 Download_button fork
public
Public Clone URL: git://gist.github.com/220746.git
Embed All Files: show embed
added-task-to-update-comments-counts-in-entries.patch #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
From 54368c5fc6f4bdecc7018462e03d1730fdf2507c Mon Sep 17 00:00:00 2001
From: Patrick Aljord <patcito@zeta.cc>
Date: Wed, 28 Oct 2009 13:28:18 -0500
Subject: [PATCH] added task to update comments counts in entries
 
---
 lib/tasks/integrity.rake | 19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)
 
diff --git a/lib/tasks/integrity.rake b/lib/tasks/integrity.rake
index 7d9c4f6..61f9c04 100644
--- a/lib/tasks/integrity.rake
+++ b/lib/tasks/integrity.rake
@@ -59,9 +59,10 @@ namespace :db do
         "torrents:kill_dtfsless_dtfms", # ran in dev, prod
         "resources:remove_dupes", # ran in dev, prod
         "features:update_features_weight", # ran in dev, prod
- "videos:resources:populate",
+ "videos:resources:populate", # ran in dev
         "torrents:downloads_count_to_zero", # ran in dev
         "torrents:new_downloads_count", # ran in dev
+ "entries:update_comments_count",
       ]
     desc "Fix timestamps that were broken before without_timestamps{...}"
     task :fix_timestamps => :environment do
@@ -760,7 +761,21 @@ namespace :db do
     end
 
     namespace :entries do
- desc "Set stickies to false"
+ desc "Update comments count"
+ task :update_comments_count => :environment do
+ Entry.reset_column_information
+ entries = Entry.find(:all)
+ Entry.transaction do
+ entries.each_with_index do |e,i|
+ puts "updating entry #{i}/#{entries.size-1}"
+ e.comments_count = e.comments.length
+ e.save
+ end
+ end
+ puts "done."
+ end
+
+ desc "Set stickies to false"
       task :set_sticky_to_false => :environment do
         sql = "UPDATE entries SET sticky='f'"
         puts "updating all entries: #{sql}"
--
1.6.4.4+GitX