aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/info_request.rb
Commit message (Collapse)AuthorAgeLines
* Fix the deadlock on dealing with incoming emailMark Longair2013-04-18-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #336 There was an occasional deadlock when two emails for the same request came in near-simultaneously; two processes would be started via script/mailin, each to deal with one email which are both updating the same InfoRequest. The error would look like: 2013-04-07 09:19:03 BST [13398]: [2-1] DETAIL: Process 13398 waits for ShareLock on transaction 36193647; blocked by process 13397. Process 13397 waits for ExclusiveLock on tuple (390,35) of relation 32918788 of database 32918687; blocked by process 13398. Process 13398: UPDATE "info_requests" SET "updated_at" = '2013-04-07 08:19:02.139515', "awaiting_description" = 't' WHERE "id" = 156200 Process 13397: UPDATE "info_requests" SET "updated_at" = '2013-04-07 08:19:02.143624', "awaiting_description" = 't' WHERE "id" = 156200 This arose from the following section of code: ActiveRecord::Base.transaction do raw_email = RawEmail.new incoming_message.raw_email = raw_email incoming_message.info_request = self incoming_message.save! raw_email.data = raw_email_data raw_email.save! self.awaiting_description = true params = { :incoming_message_id => incoming_message.id } if !rejected_reason.empty? params[:rejected_reason] = rejected_reason.to_str end self.log_event("response", params) self.save! end Matthew Somerville explained what was happening here in the issue report; to repeat his explanation from the bug report, both processes enter the transaction block and acquire a ShareLock on self with: incoming_message.info_request = self incoming_message.save! However, in order to update the self.awaiting_description field of the InfoRequest, with: self.awaiting_description = true [...] self.save! ... the ShareLock needs to be upgraded to an ExclusiveLock, but both will wait until the other's ShareLock is released, which would only happen at the end of the transaction. We can avoid this deadlock by using SELECT ... FOR UPDATE for the row in info_requests. In Rails 3.2.0 there is ActiveRecord support for this (via with_lock and lock! on a model instance) but so as not to require upgrading rails, I'm just using raw SQL.
* Refactor functionality from controller to modelMatthew Landauer2013-03-04-0/+15
|
* When setting a state optionally pass a messsageMatthew Landauer2013-03-02-2/+2
|
* Simplify method by using array to store mappingMatthew Landauer2013-03-02-39/+24
|
* InfoRequestEvent should know about its event typesMatthew Landauer2013-03-02-2/+2
|
* Extract methodMatthew Landauer2013-03-02-6/+5
|
* Simplify methodsMatthew Landauer2013-03-02-19/+7
|
* Simplify logic in methodMatthew Landauer2013-03-02-7/+2
|
* Inline methodMatthew Landauer2013-03-02-11/+1
|
* Inline methodMatthew Landauer2013-03-02-6/+1
|
* Merge remote-tracking branch 'mysociety/develop' into rails_xssMatthew Landauer2013-01-15-3/+3
|\
| * Delegate getting the from address of an incoming mail to the mail handler.Louise Crow2012-12-03-2/+2
| |
| * Standardize slug generation for external users so that it uses the same ↵Louise Crow2012-11-29-1/+1
| | | | | | | | underlying method as other slug generation. Fixes #567.
* | More escaping fixesMatthew Landauer2013-01-15-2/+2
|/
* Merge remote-tracking branch 'origin/feature/isolate-mail-handling' into developLouise Crow2012-11-20-3/+3
|\
| * Move address_from_name_and_email to mail handler.Louise Crow2012-11-15-3/+3
| |
* | Handle a request for json on a an external request - return the user_name ↵Louise Crow2012-11-19-1/+5
|/ | | | attribute instead of a full user model. Fixes #715.
* Move access to mail message id to incoming message.Louise Crow2012-11-15-2/+1
|
* Rubyise loop.Louise Crow2012-11-15-1/+1
|
* Refactor access to the mail object - only from incoming_message.Louise Crow2012-11-15-6/+1
|
* Handle the default blank string passed by Configuration moduleLouise Crow2012-10-25-1/+1
|
* Add an option to calls to calculate_status and display_status to specify ↵Louise Crow2012-10-23-7/+6
| | | | that the method can return a value cached on the object by a previous call.
* In number of requests shown on home page only include requests with normal ↵Matthew Landauer2012-10-17-0/+2
| | | | prominence
* Rename models and tables exim -> mail_serverMatthew Landauer2012-10-11-3/+3
|
* Extract configuration with defaults into one moduleMatthew Landauer2012-09-25-12/+7
|
* Merge remote-tracking branch 'openaustralia_github/calendar_days' into developLouise Crow2012-09-24-3/+5
|\
| * Make the way number of days are calculated (either by calendar or working ↵Matthew Landauer2012-09-24-3/+5
| | | | | | | | days) configurable
| * Fix: configuration for very late number of days wasn't being usedMatthew Landauer2012-09-24-2/+2
| |
| * Rename methodMatthew Landauer2012-09-24-3/+3
| |
* | Add an option to disable comments on a requestRobin Houston2012-09-19-0/+2
|/ | | | Closes #30.
* Allow InfoRequest.find_old_unclassified to accept an offset param so it can ↵Louise Crow2012-09-13-2/+3
| | | | be used in conjunction with pagination.
* Add a counter cache for the number of info_requests associated with public ↵Louise Crow2012-09-12-1/+1
| | | | bodies.
* Add some more efficient methods for getting old unclassified request counts, ↵Louise Crow2012-09-11-9/+36
| | | | and random sets of small numbers of old unclassified requests.
* Merge branch 'release/0.6.3' into developLouise Crow2012-08-22-10/+14
|\ | | | | | | | | | | | | | | Conflicts: app/controllers/admin_public_body_controller.rb app/views/admin_public_body/import_csv.rhtml spec/controllers/admin_public_body_controller_spec.rb spec/models/info_request_spec.rb
| * Apply global and public body censor rules to binary files.Louise Crow2012-08-14-9/+10
| |
| * Add association between public bodies and censor rules, have info_request ↵Louise Crow2012-08-14-1/+1
| | | | | | | | apply rules from its public body.
| * Add concept of global censor rules as orthogonal to regex censor rules. ↵Louise Crow2012-08-14-12/+15
| | | | | | | | Apply global rules to every request, not regex rules.
* | Email admins about external requests tooRobin Houston2012-08-21-2/+5
| | | | | | | | | | | | | | If someone reports an external request as needing administrator attention, we should email the administrators about it. Thanks for spotting this, @crowbot.
* | Fail with NotFound if request slug doesn't existRobin Houston2012-08-20-2/+4
| | | | | | | | Closes #554.
* | Do not send email for external requestsRobin Houston2012-08-20-2/+2
| |
* | Fix testsRobin Houston2012-08-20-1/+1
| | | | | | | | | | | | | | | | | | Also make the InfoRequest#is_old_unclassified? method a little more conservative, by returning false only is the is_external? method returns true. This makes it subtly inconsistent with InfoRequest.find_old_unclassified, but it is better I think to be subtly inconsistent than to risk breaking things that used to work.
* | External requests ought not to be considered old_unclassifiedRobin Houston2012-08-20-1/+2
| | | | | | | | | | We certainly do not want to send reminder emails for such requests, for example, since we do not know the email address to send them to.
* | Merge branch 'wdtk' into developLouise Crow2012-08-16-8/+14
|\ \ | |/ |/| | | | | | | | | Conflicts: app/controllers/admin_request_controller.rb config/httpd.conf spec/models/info_request_spec.rb
| * Add method all_can_view? which can be used to determine whether it is ok to ↵Louise Crow2012-08-16-8/+14
| | | | | | | | cache the associated objects for an info request in the file cache which will be served up without authentication.
* | Fix bug that only occurs when loading sample data - sometimes an InfoRequest ↵Seb Bacon2012-07-13-1/+1
| | | | | | | | doesn't have a PublicBody at the time its slug is being calculated.
* | Support regular expressions in CensorRules; also support 'global' ↵Seb Bacon2012-07-13-6/+3
|/ | | | CensorRules that aren't attached to a User or Request or Public Body (but don't expose this in the admin UI). Fixes #33
* WIP new requests feedRobin Houston2012-07-04-3/+3
|
* Merge branch 'develop' of github.com:sebbacon/alaveteli into developRobin Houston2012-06-23-2/+2
|\ | | | | | | | | | | | | | | Conflicts: Gemfile.lock script/handle-mail-replies script/handle-mail-replies.rb spec/controllers/request_controller_spec.rb
| * Merge branch 'master' into developSeb Bacon2012-06-20-2/+2
| |\
| | * Make emails requesting admin attention appear to come from the user who ↵Seb Bacon2012-06-12-2/+2
| | | | | | | | | | | | requested the attention, not the user who made the original request.