From c5ce14ac6818f1e72f004a86d12a04f356d46792 Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 11 Mar 2013 13:14:25 -0400 Subject: [PATCH] fixes #837 --- app/models/note.rb | 24 +++++++++++++++++++++++- app/models/post.rb | 15 +++++---------- app/models/upload.rb | 26 ++++++++++++++++++++++++++ app/models/wiki_page.rb | 24 +++++++++++++++++++++++- config/schedule.rb | 6 +++--- 5 files changed, 80 insertions(+), 15 deletions(-) diff --git a/app/models/note.rb b/app/models/note.rb index c1a0d2b2d..8290cb36d 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -58,7 +58,29 @@ class Note < ActiveRecord::Base end end + module ApiMethods + def serializable_hash(options = {}) + options ||= {} + options[:except] ||= [] + options[:except] += hidden_attributes + unless options[:builder] + options[:methods] ||= [] + options[:methods] += [:creator_name] + end + hash = super(options) + hash + end + + def to_xml(options = {}, &block) + options ||= {} + options[:procs] ||= [] + options[:procs] << lambda {|options, record| options[:builder].tag!("creator-name", record.creator_name)} + super(options, &block) + end + end + extend SearchMethods + include ApiMethods def presenter @presenter ||= NotePresenter.new(self) @@ -89,7 +111,7 @@ class Note < ActiveRecord::Base end def creator_name - User.id_to_name(creator_id) + User.id_to_name(creator_id).tr("_", " ") end def update_post diff --git a/app/models/post.rb b/app/models/post.rb index 418ec2829..f6ba27c36 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -537,7 +537,7 @@ class Post < ActiveRecord::Base end def uploader_name - User.id_to_name(uploader_id) + User.id_to_name(uploader_id).tr("_", " ") end end @@ -837,20 +837,15 @@ class Post < ActiveRecord::Base options ||= {} options[:except] ||= [] options[:except] += hidden_attributes - # options[:methods] += [:uploader_name, :has_large] + unless options[:builder] + options[:methods] ||= [] + options[:methods] += [:uploader_name, :has_large] + end hash = super(options) hash end - - def to_json(options = {}) - options ||= {} - options[:methods] ||= [] - options[:methods] += [:uploader_name, :has_large] - super(options) - end def to_xml(options = {}, &block) - # to_xml ignores the serializable_hash method options ||= {} options[:procs] ||= [] options[:procs] << lambda {|options, record| options[:builder].tag!("uploader-name", record.uploader_name)} diff --git a/app/models/upload.rb b/app/models/upload.rb index 4d598f897..421768fda 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -364,6 +364,27 @@ class Upload < ActiveRecord::Base end end + module ApiMethods + def serializable_hash(options = {}) + options ||= {} + options[:except] ||= [] + options[:except] += hidden_attributes + unless options[:builder] + options[:methods] ||= [] + options[:methods] += [:uploader_name] + end + hash = super(options) + hash + end + + def to_xml(options = {}, &block) + options ||= {} + options[:procs] ||= [] + options[:procs] << lambda {|options, record| options[:builder].tag!("uploader-name", record.uploader_name)} + super(options, &block) + end + end + include ConversionMethods include ValidationMethods include FileMethods @@ -376,6 +397,7 @@ class Upload < ActiveRecord::Base include StatusMethods include UploaderMethods extend SearchMethods + include ApiMethods def add_file_size_tags!(file_path) if file_size >= 10.megabytes @@ -383,6 +405,10 @@ class Upload < ActiveRecord::Base end end + def uploader_name + User.id_to_name(uploader_id) + end + def presenter @presenter ||= UploadPresenter.new(self) end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 30cf559aa..d20760dcd 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -52,7 +52,29 @@ class WikiPage < ActiveRecord::Base end end + module ApiMethods + def serializable_hash(options = {}) + options ||= {} + options[:except] ||= [] + options[:except] += hidden_attributes + unless options[:builder] + options[:methods] ||= [] + options[:methods] += [:creator_name] + end + hash = super(options) + hash + end + + def to_xml(options = {}, &block) + options ||= {} + options[:procs] ||= [] + options[:procs] << lambda {|options, record| options[:builder].tag!("creator-name", record.creator_name)} + super(options, &block) + end + end + extend SearchMethods + include ApiMethods def self.find_title_and_id(title) titled(title).select("title, id").first @@ -81,7 +103,7 @@ class WikiPage < ActiveRecord::Base end def creator_name - User.id_to_name(user_id).tr("_", " ") + User.id_to_name(creator_id).tr("_", " ") end def category_name diff --git a/config/schedule.rb b/config/schedule.rb index 4e6954a69..9507b887a 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -12,17 +12,17 @@ every 1.day, :at => "1:00 am" do runner "Upload.delete_all(['created_at < ?', 1.day.ago])" end -every 1.day, :at => "2:00 am" do +every 1.day, :at => "1:30 am" do runner "ModAction.delete_all(['created_at < ?', 3.days.ago])" end -every 1.day, :at => "3:00 am" do +every 1.day, :at => "2:00 am" do command "cd /var/www/danbooru2/current ; script/donmai/backup_db" command "cd /var/www/danbooru2/current ; script/donmai/backup_db_to_s3" command "cd /var/www/danbooru2/current ; script/donmai/prune_backup_dbs" end -every 1.day, :at => "4:00 am" do +every 1.day, :at => "3:00 am" do command "psql --set-statement-timeout=0 -hdbserver -c \"vacuum analyze verbose;\" danbooru2" end