From f58bcf7fe321fc72e742281085933e05c09b6fec Mon Sep 17 00:00:00 2001 From: Janis Miezitis Date: Sun, 26 May 2013 16:07:20 +0300 Subject: [PATCH] Refactored duplication in user action --- app/models/user_action.rb | 47 ++++++++++++++------------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/app/models/user_action.rb b/app/models/user_action.rb index e88b698f7b9..7c8cc07bb59 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -114,21 +114,7 @@ LEFT JOIN categories c on c.id = t.category_id builder.limit(limit.to_i) data = builder.exec.to_a end - - data.each do |row| - row["action_type"] = row["action_type"].to_i - row["created_at"] = DateTime.parse(row["created_at"]) - # we should probably cache the excerpts in the db at some point - row["excerpt"] = PrettyText.excerpt(row["cooked"],300) if row["cooked"] - row["cooked"] = nil - row["avatar_template"] = User.avatar_template(row["email"]) - row["acting_avatar_template"] = User.avatar_template(row["acting_email"]) - row.delete("email") - row.delete("acting_email") - row["slug"] = Slug.for(row["title"]) - end - - data + normalize_builder_data(data) end # slightly different to standard stream, it collapses replies @@ -164,21 +150,7 @@ ORDER BY p.created_at desc data = builder.exec(user_id: user_id, action_type: action_type).to_a - data.each do |row| - row["action_type"] = row["action_type"].to_i - row["created_at"] = DateTime.parse(row["created_at"]) - # we should probably cache the excerpts in the db at some point - row["excerpt"] = PrettyText.excerpt(row["cooked"],300) if row["cooked"] - row["cooked"] = nil - row["avatar_template"] = User.avatar_template(row["email"]) - row["acting_avatar_template"] = User.avatar_template(row["acting_email"]) - row.delete("email") - row.delete("acting_email") - row["slug"] = Slug.for(row["title"]) - end - - data - + normalize_builder_data(data) end def self.log_action!(hash) @@ -237,6 +209,21 @@ ORDER BY p.created_at desc end protected + + def self.normalize_builder_data(data) + data.each do |row| + row["action_type"] = row["action_type"].to_i + row["created_at"] = DateTime.parse(row["created_at"]) + # we should probably cache the excerpts in the db at some point + row["excerpt"] = PrettyText.excerpt(row["cooked"],300) if row["cooked"] + row["cooked"] = nil + row["avatar_template"] = User.avatar_template(row["email"]) + row["acting_avatar_template"] = User.avatar_template(row["acting_email"]) + row.delete("email") + row.delete("acting_email") + row["slug"] = Slug.for(row["title"]) + end + end def self.apply_common_filters(builder,user_id,guardian,ignore_private_messages=false)