aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--app/controllers/application_controller.rb17
-rw-r--r--app/models/info_request.rb9
-rw-r--r--app/models/raw_email.rb1
-rw-r--r--app/models/track_mailer.rb6
-rw-r--r--config/general.yml-example6
-rw-r--r--db/migrate/099_move_raw_email_to_filesystem.rb6
-rw-r--r--db/migrate/100_remove_redundant_raw_email_columns.rb14
8 files changed, 41 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index 8fabc641a..e8317395f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,4 @@ moo.txt
TAGS
/vendor/plugins/*theme
/locale/model_attributes.rb
+/files/ \ No newline at end of file
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 405327952..fe9ed7ec7 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -46,12 +46,17 @@ class ApplicationController < ActionController::Base
# egrep "CONSUME MEMORY: [0-9]{7} KB" production.log
around_filter :record_memory
def record_memory
- File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/)
- rss_before_action = $1.to_i
- yield
- File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/)
- rss_after_action = $1.to_i
- logger.info("PID: #{Process.pid}\tCONSUME MEMORY: #{rss_after_action - rss_before_action} KB\tNow: #{rss_after_action} KB\t#{request.url}")
+ record_memory = MySociety::Config.get('DEBUG_RECORD_MEMORY', false)
+ if record_memory
+ File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/)
+ rss_before_action = $1.to_i
+ yield
+ File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/)
+ rss_after_action = $1.to_i
+ logger.info("PID: #{Process.pid}\tCONSUME MEMORY: #{rss_after_action - rss_before_action} KB\tNow: #{rss_after_action} KB\t#{request.url}")
+ else
+ yield
+ end
end
# Set cookie expiry according to "remember me" checkbox, as per "An easier
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 9182b6ae7..e6a520fd2 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -347,14 +347,7 @@ public
# XXX this *should* also check outgoing message joined to is an initial
# request (rather than follow up)
def InfoRequest.find_by_existing_request(title, public_body_id, body)
- # XXX can add other databases here which have regexp_replace
- if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
- # Exclude spaces from the body comparison using regexp_replace
- return InfoRequest.find(:first, :conditions => [ "title = ? and public_body_id = ? and regexp_replace(outgoing_messages.body, '[[:space:]]', '', 'g') = regexp_replace(?, '[[:space:]]', '', 'g')", title, public_body_id, body ], :include => [ :outgoing_messages ] )
- else
- # For other databases (e.g. SQLite) not the end of the world being space-sensitive for this check
- return InfoRequest.find(:first, :conditions => [ "title = ? and public_body_id = ? and outgoing_messages.body = ?", title, public_body_id, body ], :include => [ :outgoing_messages ] )
- end
+ return InfoRequest.find(:first, :conditions => [ "title = ? and public_body_id = ? and outgoing_messages.body = ?", title, public_body_id, body ], :include => [ :outgoing_messages ] )
end
def find_existing_outgoing_message(body)
diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb
index 7a57399d5..4e1a69456 100644
--- a/app/models/raw_email.rb
+++ b/app/models/raw_email.rb
@@ -6,7 +6,6 @@
# id :integer not null, primary key
# data_text :text
# data_binary :binary
-# - prepared to 277k.
# models/raw_email.rb:
# The fat part of models/incoming_message.rb
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb
index 1b37709b9..6901a834d 100644
--- a/app/models/track_mailer.rb
+++ b/app/models/track_mailer.rb
@@ -26,7 +26,11 @@ class TrackMailer < ApplicationMailer
@body = { :user => user, :email_about_things => email_about_things, :unsubscribe_url => unsubscribe_url }
end
- # Send email alerts for tracked things.
+ # Send email alerts for tracked things. Never more than one email
+ # a day, nor about events which are more than a week old, nor
+ # events about which emails have been sent within the last two
+ # weeks.
+
# Useful query to run by hand to see how many alerts are due:
# User.find(:all, :conditions => [ "last_daily_track_email < ?", Time.now - 1.day ]).size
def self.alert_tracks
diff --git a/config/general.yml-example b/config/general.yml-example
index 60a527302..fb2afd336 100644
--- a/config/general.yml-example
+++ b/config/general.yml-example
@@ -87,3 +87,9 @@ STAGING_SITE: 1
RECAPTCHA_PUBLIC_KEY: 'x'
RECAPTCHA_PRIVATE_KEY: 'x'
+# For debugging memory problems. If true, the app logs
+# the memory use increase of the Ruby process due to the
+# request (Linux only). Since Ruby never returns memory to the OS, if the
+# existing process previously served a larger request, this won't
+# show any consumption for the later request.
+DEBUG_RECORD_MEMORY: false \ No newline at end of file
diff --git a/db/migrate/099_move_raw_email_to_filesystem.rb b/db/migrate/099_move_raw_email_to_filesystem.rb
index 991ef55d7..ea77580e1 100644
--- a/db/migrate/099_move_raw_email_to_filesystem.rb
+++ b/db/migrate/099_move_raw_email_to_filesystem.rb
@@ -6,15 +6,15 @@ class MoveRawEmailToFilesystem < ActiveRecord::Migration
if !File.exists?(raw_email.filepath)
STDERR.puts "converting raw_email " + raw_email.id.to_s
raw_email.data = raw_email.dbdata
- raw_email.dbdata = nil
- raw_email.save!
+ #raw_email.dbdata = nil
+ #raw_email.save!
end
end
end
end
def self.down
- #raise "safer not to have reverse migration scripts, and we never use them"
+ raise "safer not to have reverse migration scripts, and we never use them"
end
end
diff --git a/db/migrate/100_remove_redundant_raw_email_columns.rb b/db/migrate/100_remove_redundant_raw_email_columns.rb
new file mode 100644
index 000000000..b8f9454f6
--- /dev/null
+++ b/db/migrate/100_remove_redundant_raw_email_columns.rb
@@ -0,0 +1,14 @@
+class RemoveRedundantRawEmailColumns < ActiveRecord::Migration
+ def self.up
+ ActiveRecord::Base.connection.execute("ALTER TABLE raw_emails DROP COLUMN data_text")
+ ActiveRecord::Base.connection.execute("ALTER TABLE raw_emails DROP COLUMN data_binary")
+ end
+
+ def self.down
+ raise "safer not to have reverse migration scripts, and we never use them"
+ end
+end
+
+
+
+