aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2009-09-10 13:34:34 +0000
committerfrancis <francis>2009-09-10 13:34:34 +0000
commit3fcc1e0700fa27b556788e38e1c3ca404c469816 (patch)
treed3d35ee1dc20ca2aac464055f6f1a2329f14c444
parent0bc4aa7a0fe03d1486abe9b6633741f00af40bde (diff)
Generate these static tables not in the functions, so they don't get made
each time function is called (and they never got freed then for some reason)
-rw-r--r--app/models/public_body.rb22
1 files changed, 6 insertions, 16 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 894038853..1ab9ecf37 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -26,7 +26,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: public_body.rb,v 1.153 2009-09-08 23:48:29 francis Exp $
+# $Id: public_body.rb,v 1.154 2009-09-10 13:34:34 francis Exp $
require 'csv'
require 'set'
@@ -44,8 +44,7 @@ class PublicBody < ActiveRecord::Base
has_many :public_body_tags
has_many :track_things, :order => 'created_at desc'
- def self.categories_with_headings
- [
+ categories_with_headings = [
"Miscellaneous",
[ "other", "Miscellaneous", "miscellaneous" ],
"Central government",
@@ -119,19 +118,10 @@ class PublicBody < ActiveRecord::Base
[ "scp", "Safety Camera Partnerships", "a safety camera partnership" ],
[ "srp", "Safer Roads Partnership", "a safer roads partnership" ]
]
- end
- def self.categories_with_description
- self.categories_with_headings.select() { |a| a.instance_of?(Array) }
- end
- def self.categories
- self.categories_with_description.map() { |a| a[0] }
- end
- def self.categories_by_tag
- Hash[*self.categories_with_description.map() { |a| a[0..1] }.flatten]
- end
- def self.category_singular_by_tag
- Hash[*self.categories_with_description.map() { |a| [a[0],a[2]] }.flatten]
- end
+ categories_with_description = categories_with_headings.select() { |a| a.instance_of?(Array) }
+ categories = categories_with_description.map() { |a| a[0] }
+ categories_by_tag = Hash[*categories_with_description.map() { |a| a[0..1] }.flatten]
+ category_singular_by_tag = Hash[*categories_with_description.map() { |a| [a[0],a[2]] }.flatten]
# like find_by_url_name but also search historic url_name if none found
def self.find_by_url_name_with_historic(name)