From daf39e2287067b0fde275f674a5503dde7349b06 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Mon, 9 Jan 2012 11:13:47 +0000 Subject: Send email notifications on exceptions --- app/controllers/application_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b7457c48e..e30a7330e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,7 +14,10 @@ class ApplicationController < ActionController::Base # Standard headers, footers and navigation for whole site layout "default" include FastGettext::Translation # make functions like _, n_, N_ etc available) - + + # Send notification email on exceptions + include ExceptionNotification::Notifiable + # Note: a filter stops the chain if it redirects or renders something before_filter :authentication_check before_filter :set_gettext_locale @@ -119,6 +122,7 @@ class ApplicationController < ActionController::Base @status = 404 else @status = 500 + notify_about_exception exception end # Display user appropriate error message @exception_backtrace = exception.backtrace.join("\n") -- cgit v1.2.3 From 7610f8316a841a81b3c55cda3ac39610b3a0c267 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Mon, 9 Jan 2012 13:06:25 +0000 Subject: Ignore last-seen-item variables for the purposes of varnish caching. Fixes issue #324. --- app/controllers/application_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e30a7330e..b0351f7d1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -365,14 +365,14 @@ class ApplicationController < ActionController::Base # Store last visited pages, for contact form; but only for logged in users, as otherwise this breaks caching def set_last_request(info_request) if !session[:user_id].nil? - session[:last_request_id] = info_request.id - session[:last_body_id] = nil + cookies["last_request_id"] = info_request.id + cookies["last_body_id"] = nil end end def set_last_body(public_body) if !session[:user_id].nil? - session[:last_request_id] = nil - session[:last_body_id] = public_body.id + cookies["last_request_id"] = nil + cookies["last_body_id"] = public_body.id end end -- cgit v1.2.3 From ba07a044614a1648eaa176436346a3aed7f4ac74 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 11 Jan 2012 11:53:40 +0000 Subject: Fix problem with typeahead searches containing " - " characters and similar. Closes #328 --- app/controllers/application_controller.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b0351f7d1..8fd2da54a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -361,6 +361,27 @@ class ApplicationController < ActionController::Base def get_search_page_from_params return (params[:page] || "1").to_i end + def perform_search_typeahead(query, model) + # strip out unintended search operators - see + # https://github.com/sebbacon/alaveteli/issues/328 + # XXX this is a result of the OR hack below -- should fix by + # allowing a parameter to perform_search to control the + # default operator! + query = query.gsub(/(\s-\s|&)/, "") + query = query.split(/ +(?!-)/) + if query.last.nil? || query.last.strip.length < 3 + xapian_requests = nil + else + query = query.join(' OR ') # XXX: HACK for OR instead of default AND! + if model == PublicBody + collapse = nil + elsif model == InfoRequestEvent + collapse = 'request_collapse' + end + xapian_requests = perform_search([model], query, 'relevant', collapse, 5) + end + return xapian_requests + end # Store last visited pages, for contact form; but only for logged in users, as otherwise this breaks caching def set_last_request(info_request) -- cgit v1.2.3 From 43bd77a1ad43d7cb24117bf3973f841221fd2c6e Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 12 Jan 2012 07:47:16 +0000 Subject: Return 403 when attachment "folders" are spidered. Fixes #340 --- app/controllers/application_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8fd2da54a..05f88a6b2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -11,6 +11,8 @@ require 'open-uri' class ApplicationController < ActionController::Base + class PermissionDenied < StandardError + end # Standard headers, footers and navigation for whole site layout "default" include FastGettext::Translation # make functions like _, n_, N_ etc available) @@ -120,6 +122,8 @@ class ApplicationController < ActionController::Base case exception when ActiveRecord::RecordNotFound, ActionController::UnknownAction, ActionController::RoutingError @status = 404 + when PermissionDenied + @status = 403 else @status = 500 notify_about_exception exception @@ -189,7 +193,7 @@ class ApplicationController < ActionController::Base return File.exists?(key_path) end def foi_fragment_cache_read(key_path) - cached = File.read(key_path) + return File.read(key_path) end def foi_fragment_cache_write(key_path, content) FileUtils.mkdir_p(File.dirname(key_path)) -- cgit v1.2.3 From 21ee1ca03faa722119a3c7e587a843b960783096 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 12 Jan 2012 11:20:40 +0000 Subject: Further fix for issue #328. --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 05f88a6b2..7aa522389 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -371,8 +371,8 @@ class ApplicationController < ActionController::Base # XXX this is a result of the OR hack below -- should fix by # allowing a parameter to perform_search to control the # default operator! - query = query.gsub(/(\s-\s|&)/, "") - query = query.split(/ +(?!-)/) + query = query.strip.gsub(/(\s-\s|&)/, "") + query = query.split(/ +(?![-+]+)/) if query.last.nil? || query.last.strip.length < 3 xapian_requests = nil else -- cgit v1.2.3 From ec7a0c92f2b09c6b4d4d747d0b492bf9bd45c8ac Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 13 Jan 2012 10:31:23 +0000 Subject: Fix further special character searches as per issue #328 --- app/controllers/application_controller.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7aa522389..24268db90 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -372,6 +372,7 @@ class ApplicationController < ActionController::Base # allowing a parameter to perform_search to control the # default operator! query = query.strip.gsub(/(\s-\s|&)/, "") + query = query.strip.gsub(/(\s-\s|&|\(|\))/, "") query = query.split(/ +(?![-+]+)/) if query.last.nil? || query.last.strip.length < 3 xapian_requests = nil -- cgit v1.2.3 From b327f193cf34ec007627362cdeebc54b2fb2432b Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 13 Jan 2012 11:18:47 +0000 Subject: Correction to commit 4808347cb65556756d38b60b25fa9761f92c4513 --- app/controllers/application_controller.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 24268db90..ca6e2ba64 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -371,7 +371,6 @@ class ApplicationController < ActionController::Base # XXX this is a result of the OR hack below -- should fix by # allowing a parameter to perform_search to control the # default operator! - query = query.strip.gsub(/(\s-\s|&)/, "") query = query.strip.gsub(/(\s-\s|&|\(|\))/, "") query = query.split(/ +(?![-+]+)/) if query.last.nil? || query.last.strip.length < 3 -- cgit v1.2.3 From cec2c545e0a10e0641c4ee67839c88d872b394b8 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 13 Jan 2012 11:49:00 +0000 Subject: Ensure we show "all requests" in order that they were last updated. FIxes #343. --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ca6e2ba64..4e2afed5a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -435,7 +435,7 @@ class ApplicationController < ActionController::Base params[:latest_status] = [params[:latest_status]] end if params[:latest_status].include?("recent") || params[:latest_status].include?("all") - query += " variety:sent" + query += " variety:sent OR variety:followup_sent OR variety:response OR variety:comment" end if params[:latest_status].include? "successful" statuses << ['latest_status:successful', 'latest_status:partially_successful'] -- cgit v1.2.3 From 08dd56bac73ce83fcb12e4776b32c4e0ce75545a Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 13 Jan 2012 11:50:21 +0000 Subject: Show internal_review (and some other) items in the "unresolved" list. Fixes #344. --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4e2afed5a..f3406ee8a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -444,7 +444,7 @@ class ApplicationController < ActionController::Base statuses << ['latest_status:rejected', 'latest_status:not_held'] end if params[:latest_status].include? "awaiting" - statuses << ['latest_status:waiting_response', 'latest_status:waiting_clarification', 'waiting_classification:true'] + statuses << ['latest_status:waiting_response', 'latest_status:waiting_clarification', 'waiting_classification:true', 'latest_status:internal_review','latest_status:gone_postal', 'latest_status:error_message', 'latest_status:requires_admin'] end if params[:latest_status].include? "internal_review" statuses << ['status:internal_review'] -- cgit v1.2.3 From 07068037e9b0ac8de80a9eae36a323689c83139d Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 13 Jan 2012 13:28:23 +0000 Subject: Fix bug introduced in cec2c545e0a10e0641c4ee67839c88d872b394b8, related to issue #343. --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f3406ee8a..2633aca4d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -435,7 +435,7 @@ class ApplicationController < ActionController::Base params[:latest_status] = [params[:latest_status]] end if params[:latest_status].include?("recent") || params[:latest_status].include?("all") - query += " variety:sent OR variety:followup_sent OR variety:response OR variety:comment" + query += " (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)" end if params[:latest_status].include? "successful" statuses << ['latest_status:successful', 'latest_status:partially_successful'] -- cgit v1.2.3 From 3b0222d887e2ef1bd508e505b2327f8c2acac1d3 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 17 Jan 2012 11:30:56 +0000 Subject: Fail silently if third party services are broken or unavailable. Fixes #354. --- app/controllers/application_controller.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2633aca4d..f6068120d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -504,12 +504,22 @@ class ApplicationController < ActionController::Base default = MySociety::Config.get('ISO_COUNTRY_CODE', '') country = "" if !gaze.empty? - country = open("#{gaze}/gaze-rest?f=get_country_from_ip;ip=#{request.remote_ip}").read.strip + country = quietly_try_to_open("#{gaze}/gaze-rest?f=get_country_from_ip;ip=#{request.remote_ip}") end country = default if country.empty? return country end + def quietly_try_to_open(url) + begin + result = open(url).read.strip + rescue OpenURI::HTTPError, SocketError + logger.warn("Unable to open third-party URL #{url}") + result = "" + end + return result + end + # URL generating functions are needed by all controllers (for redirects), # views (for links) and mailers (for use in emails), so include them into # all of all. -- cgit v1.2.3 From c8a68219c541840b5c5f56cd75c1e84de6c15fe5 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 17 Jan 2012 12:50:30 +0000 Subject: Actually do a proper ORed and partial match query, rather than fix parsing errors ad hoc as I find them that result from the workaround code. Fixes #328 (for good, I hope). --- app/controllers/application_controller.rb | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f6068120d..0c8544932 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -366,23 +366,31 @@ class ApplicationController < ActionController::Base return (params[:page] || "1").to_i end def perform_search_typeahead(query, model) - # strip out unintended search operators - see - # https://github.com/sebbacon/alaveteli/issues/328 - # XXX this is a result of the OR hack below -- should fix by - # allowing a parameter to perform_search to control the - # default operator! - query = query.strip.gsub(/(\s-\s|&|\(|\))/, "") - query = query.split(/ +(?![-+]+)/) - if query.last.nil? || query.last.strip.length < 3 + query_words = query.split(/ +(?![-+]+)/) + if query_words.last.nil? || query_words.last.strip.length < 3 xapian_requests = nil else - query = query.join(' OR ') # XXX: HACK for OR instead of default AND! if model == PublicBody collapse = nil elsif model == InfoRequestEvent collapse = 'request_collapse' end - xapian_requests = perform_search([model], query, 'relevant', collapse, 5) + options = { + :offset => 0, + :limit => 5, + :sort_by_prefix => nil, + :sort_by_ascending => true, + :collapse_by_prefix => collapse, + } + ActsAsXapian.readable_init + old_default_op = ActsAsXapian.query_parser.default_op + ActsAsXapian.query_parser.default_op = Xapian::Query::OP_OR + user_query = ActsAsXapian.query_parser.parse_query( + query, + Xapian::QueryParser::FLAG_LOVEHATE | Xapian::QueryParser::FLAG_PARTIAL | + Xapian::QueryParser::FLAG_SPELLING_CORRECTION) + xapian_requests = ActsAsXapian::Search.new([model], query, options, user_query) + ActsAsXapian.query_parser.default_op = old_default_op end return xapian_requests end -- cgit v1.2.3 From b50adc72e533a9c20aca03063a676f6af4d32b85 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 18 Jan 2012 08:46:06 +0000 Subject: Fix paging bug for type ahead search. This wasn't caught because the spec didn't call "integrate_views", so the rendering part was mocked by RSpec instead of executed. --- app/controllers/application_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0c8544932..2cdd5ee35 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -365,7 +365,10 @@ class ApplicationController < ActionController::Base def get_search_page_from_params return (params[:page] || "1").to_i end + def perform_search_typeahead(query, model) + @page = get_search_page_from_params + @per_page = 10 query_words = query.split(/ +(?![-+]+)/) if query_words.last.nil? || query_words.last.strip.length < 3 xapian_requests = nil @@ -376,8 +379,8 @@ class ApplicationController < ActionController::Base collapse = 'request_collapse' end options = { - :offset => 0, - :limit => 5, + :offset => (@page - 1) * @per_page, + :limit => @per_page, :sort_by_prefix => nil, :sort_by_ascending => true, :collapse_by_prefix => collapse, -- cgit v1.2.3 From 936c3b2fb1365e46239ff98ab962460d0c459730 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 18 Jan 2012 09:07:44 +0000 Subject: Catch timeouts and other extra errors when connection to 3rd party websites fails. --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2cdd5ee35..1c73f06a7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -524,7 +524,7 @@ class ApplicationController < ActionController::Base def quietly_try_to_open(url) begin result = open(url).read.strip - rescue OpenURI::HTTPError, SocketError + rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH logger.warn("Unable to open third-party URL #{url}") result = "" end -- cgit v1.2.3 From e06ab9fcc47addc2f397070414a60172080bdd84 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 19 Jan 2012 12:49:20 +0000 Subject: Don't choke on very long filenames when caching attachments. Fixes #349. --- app/controllers/application_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0c8544932..2108b9d45 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -180,7 +180,10 @@ class ApplicationController < ActionController::Base path = foi_fragment_cache_part_path(param) path = "/views" + path foi_cache_path = File.join(File.dirname(__FILE__), '../../cache') - return File.join(foi_cache_path, path) + max_file_length = 255 - 35 # we subtract 35 because tempfile + # adds on a variable number of + # characters + return File.join(foi_cache_path, path)[0...max_file_length] end def foi_fragment_cache_all_for_request(info_request) # return stub path so admin can expire it -- cgit v1.2.3 From 22b2db48c005be1d1b87dd6b58f830a2a74d2108 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Thu, 19 Jan 2012 13:50:26 +0000 Subject: Limit Xapian wildcard expansions Wildcard searches in Xapian can expand uncontrollably, consuming all available RAM and crashing the server. This has been a real problem on WhatDoTheyKnow.com. The underlying issue is tracked in http://trac.xapian.org/ticket/350 This changeset imposes a limit on wildcard expansion. The type-ahead search will first try a wildcard query, and if that fails because of too much expansion will fall back to a plain non-wildcard search. --- app/controllers/application_controller.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0c8544932..eae27c667 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -385,11 +385,24 @@ class ApplicationController < ActionController::Base ActsAsXapian.readable_init old_default_op = ActsAsXapian.query_parser.default_op ActsAsXapian.query_parser.default_op = Xapian::Query::OP_OR - user_query = ActsAsXapian.query_parser.parse_query( - query, - Xapian::QueryParser::FLAG_LOVEHATE | Xapian::QueryParser::FLAG_PARTIAL | - Xapian::QueryParser::FLAG_SPELLING_CORRECTION) - xapian_requests = ActsAsXapian::Search.new([model], query, options, user_query) + begin + user_query = ActsAsXapian.query_parser.parse_query( + query.strip + '*', + Xapian::QueryParser::FLAG_LOVEHATE | Xapian::QueryParser::FLAG_WILDCARD | + Xapian::QueryParser::FLAG_SPELLING_CORRECTION) + xapian_requests = ActsAsXapian::Search.new([model], query, options, user_query) + rescue RuntimeError => e + if e.message =~ /^QueryParserError: Wildcard/ + # Wildcard expands to too many terms + logger.info "Wildcard query '#{query.strip + '*'}' caused: #{e.message}" + + user_query = ActsAsXapian.query_parser.parse_query( + query, + Xapian::QueryParser::FLAG_LOVEHATE | + Xapian::QueryParser::FLAG_SPELLING_CORRECTION) + xapian_requests = ActsAsXapian::Search.new([model], query, options, user_query) + end + end ActsAsXapian.query_parser.default_op = old_default_op end return xapian_requests -- cgit v1.2.3 From fa7a9d6262c84951cbe5992e1da4269aeb3a95f7 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Thu, 19 Jan 2012 17:32:47 +0000 Subject: Record URL and PID *before* a request is processed (If DEBUG_RECORD_MEMORY is enabled) This is useful for tracking down bugs that cause Rails to go into an infinite or very long loop, as the recent Xapian wildcard bug does. --- app/controllers/application_controller.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c38ab594d..d3ea7493b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -89,6 +89,7 @@ class ApplicationController < ActionController::Base def record_memory record_memory = MySociety::Config.get('DEBUG_RECORD_MEMORY', false) if record_memory + logger.info "Processing request for #{request.url} with Rails process #{Process.pid}" File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/) rss_before_action = $1.to_i yield -- cgit v1.2.3 From fc294a8dab42dad75cabcd21e2793d4073d41f79 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Sat, 21 Jan 2012 11:02:15 +0000 Subject: Logging for fragment cache --- app/controllers/application_controller.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d3ea7493b..8fc6c3792 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -197,10 +197,12 @@ class ApplicationController < ActionController::Base return File.exists?(key_path) end def foi_fragment_cache_read(key_path) + logger.info "Reading from fragment cache #{key_path}" return File.read(key_path) end def foi_fragment_cache_write(key_path, content) FileUtils.mkdir_p(File.dirname(key_path)) + logger.info "Writing to fragment cache #{key_path}" File.atomic_write(key_path) do |f| f.write(content) end -- cgit v1.2.3 From 347a24ccfe0881b494044778cae64809d3e001c0 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Fri, 27 Jan 2012 09:36:02 +0000 Subject: More test data and a new test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a test for what I thought issue #370 might be. However this test is passing, so it isn’t that. --- app/controllers/application_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8fc6c3792..5a295d3e7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -178,14 +178,13 @@ class ApplicationController < ActionController::Base end def foi_fragment_cache_path(param) - path = foi_fragment_cache_part_path(param) - path = "/views" + path - foi_cache_path = File.join(File.dirname(__FILE__), '../../cache') + path = File.join(RAILS_ROOT, 'cache', 'views', foi_fragment_cache_part_path(param)) max_file_length = 255 - 35 # we subtract 35 because tempfile # adds on a variable number of # characters - return File.join(foi_cache_path, path)[0...max_file_length] + return File.join(File.split(path).map{|x| x[0...max_file_length]}) end + def foi_fragment_cache_all_for_request(info_request) # return stub path so admin can expire it first_three_digits = info_request.id.to_s()[0..2] -- cgit v1.2.3 From 11f45e188c59c8ad272a9fa611b387c54fcec80a Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Sun, 29 Jan 2012 19:05:21 +0000 Subject: Irrelevant change So, well, I found this change when I ran git diff; and the truth is that I just prefer it aesthetically. Is that so sinful? --- app/controllers/application_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5a295d3e7..1849f23f3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -354,9 +354,7 @@ class ApplicationController < ActionController::Base @sortby = sortby # Work out sorting method - order_pair = order_to_sort_by(@sortby) - order = order_pair[0] - ascending = order_pair[1] + order, ascending = order_to_sort_by(@sortby) # Peform the search @per_page = per_page -- cgit v1.2.3 From 33f8ef66084bbfb61bf0b4e0f53e1da5e7cc84dc Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Tue, 31 Jan 2012 23:33:05 +0000 Subject: Close xapian db before opening it again This *ought* to fix the problem with the alert-tracks daemon opening more and more copies of the xapian db till it exhausts the available file descriptors. --- app/controllers/application_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1849f23f3..b681f455d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -363,7 +363,10 @@ class ApplicationController < ActionController::Base else @page = this_page end - return InfoRequest.full_search(models, @query, order, ascending, collapse, @per_page, @page) + result = InfoRequest.full_search(models, @query, order, ascending, collapse, @per_page, @page) + result.results # Touch the results to load them, otherwise accessing them from the view + # might fail later if the database has subsequently been reopened. + return result end def get_search_page_from_params return (params[:page] || "1").to_i -- cgit v1.2.3