Skip to content

Commit

Permalink
remove FinancialTransaction#full_table_count, remove straight SQL query
Browse files Browse the repository at this point in the history
  • Loading branch information
James McKinney committed Jul 23, 2012
1 parent 5348218 commit 05b2455
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/controllers/financial_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def index
@organisation = params[:organisation_type].constantize.find(params[:organisation_id]) if params[:organisation_type] && params[:organisation_id]
@title = (@organisation ? "#{@organisation.title} " : "") + "Transactions :: Spending Data :: Page #{page}"
@financial_transactions = @organisation ? @organisation.payments.paginate(:page => page, :order => 'value DESC') :
FinancialTransaction.paginate(:page => page, :order => 'value DESC', :total_entries => FinancialTransaction.full_table_count)
FinancialTransaction.paginate(:page => page, :order => 'value DESC', :total_entries => FinancialTransaction.count(:id))
respond_to do |format|
format.html
format.xml do
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/planning_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def index
# bounds=Geokit::Bounds.from_point_and_radius(@postcode, distance)
# @planning_applications = PlanningApplication.find(:all, :bounds => bounds)

# @todo after switch to PostGIS, paginate and sort, like when searching by council ID
# @todo PostGIS: after switch, paginate and sort like when searching by council ID
@planning_applications = PlanningApplication.find(:all, :origin => [@postcode.lat, @postcode.lng],
:within => distance)
@title = "Planning Applications within #{distance} km of #{params[:postcode]}"
Expand Down
4 changes: 0 additions & 4 deletions app/models/financial_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ def self.export_spending_data
# FileUtils.chmod_R 0644, "#{csv_file}.zip"
end

def self.full_table_count
count(:from =>"financial_transactions USE INDEX(index_financial_transactions_on_supplier_id)")
end

def averaged_date_and_value
return [[date, value]] unless date_fuzziness?
first_date, last_date = (date - date_fuzziness), (date + date_fuzziness)
Expand Down
4 changes: 2 additions & 2 deletions app/models/spending_stat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def calculated_transaction_count
def calculated_earliest_transaction_date
return unless organisation.respond_to?(:payments)
return @calculated_earliest_transaction_date if @calculated_earliest_transaction_date
# extra_params = organisation.is_a?(Supplier) ? {} : {:from => 'financial_transactions FORCE INDEX(index_financial_transactions_on_date)'}
# extra_params = organisation.is_a?(Supplier) ? {} : {:from => 'financial_transactions FORCE INDEX(index_financial_transactions_on_date)'} # @note PostgreSQL-incompatible
extra_params={}
return unless first_transaction = organisation.payments.earliest.first(extra_params)
@calculated_earliest_transaction_date = first_transaction.date - first_transaction.date_fuzziness.to_i.days
Expand All @@ -100,7 +100,7 @@ def calculated_earliest_transaction_date
def calculated_latest_transaction_date
return unless organisation.respond_to?(:payments)
return @calculated_latest_transaction_date if @calculated_latest_transaction_date
# extra_params = organisation.is_a?(Supplier) ? {} : {:from => 'financial_transactions FORCE INDEX(index_financial_transactions_on_date)'}
# extra_params = organisation.is_a?(Supplier) ? {} : {:from => 'financial_transactions FORCE INDEX(index_financial_transactions_on_date)'} # @note PostgreSQL-incompatible
extra_params={}
return unless last_transaction = organisation.payments.latest.first(extra_params)
@calculated_latest_transaction_date = last_transaction.date + last_transaction.date_fuzziness.to_i.days
Expand Down
2 changes: 1 addition & 1 deletion app/views/main/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<li><%= link_to "#{HyperlocalSite.approved.size} hyperlocal sites", hyperlocal_sites_path %></li>
<li><%= number_with_delimiter(Document.count) %> documents</li>
<li>Over <%= number_with_delimiter(Datapoint.count) %> pieces of data</li>
<li><%= link_to "#{number_with_delimiter(FinancialTransaction.full_table_count)} financial transactions", :controller => 'councils', :action => 'spending' %></li>
<li><%= link_to "#{number_with_delimiter(FinancialTransaction.count(:id))} financial transactions", :controller => 'councils', :action => 'spending' %></li>
</ul>
</div>
<p class="clear-left">Most of the data is accessible as <%= link_to "XML", 'http://en.wikipedia.org/wiki/XML', :class => 'external' %> or <%= link_to "json", 'http://en.wikipedia.org/wiki/JSON', :class => 'external' %> data through a <%= link_to "simple API", :controller => "info", :action => "api" %> (basically add .xml or .json to the main part of the URL). There is also a <a href="http://countculture.wordpress.com/2009/10/09/openlylocal-info-on-your-website-part-1-google-gadgets/" title="OpenlyLocal info on your website, Part 1: Google Gadgets &laquo; countculture">Google Gadget</a>, an <a href="http://blog.openlylocal.com/2009/11/20/openlylocal-info-on-your-hyperlocal-website-part-2-ning-app/" title="OpenlyLocal info on your hyperlocal website, Part 2: Ning app &laquo; countculture">app for Hyperlocal sites using Ning</a>, and <a href="http://countculture.wordpress.com/2010/04/17/expirimental-openlylocal-widget-council-info-on-any-website/" title="Experimental OpenlyLocal widget: council info on any website &laquo; countculture">a simple javascript widget</a></p>
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/temp_migration_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,7 @@ end
task :remove_duplicate_planning_applications => :environment do
Council.all.each do |council|
next if council.planning_applications.count == 0
sql= "SELECT `planning_applications`.uid, count(id) AS uid_count FROM `planning_applications` WHERE (`planning_applications`.`council_id` = #{council.id}) GROUP BY uid HAVING uid_count > 1"
dup_uids = PlanningApplication.connection.select_rows(sql).collect{|row| row.first}
dup_uids = PlanningApplication.count(:select => :uid, :conditions => {:council_id => council.id}, :group => :uid, :having => 'count_uid > 1').keys
destroy_count = 0
dup_uids.each do |uid|
destroy_count += PlanningApplication.find_all_by_council_id_and_uid(council.id, uid)[1..-1].each(&:destroy).size
Expand All @@ -526,6 +525,7 @@ task :remove_duplicate_planning_applications => :environment do
end
end

# @todo PostGIS update this code
task :convert_old_confirmed_planning_alert_subscribers => :environment do
sql= "SELECT COUNT(*) FROM planning_alert_subscribers WHERE confirmed = 1 LIMIT 10"
connection = AlertSubscriber.connection
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ $(document).ready( function() {

/* Planning alerts */
/*
// @todo uncomment after switch to PostGIS
// @todo PostGIS: uncomment after switch
$('#alert_subscriber_postcode_text,#new_alert_subscriber input:radio').change(function (event) {
var $header = $('#planning-alerts-preview h2'),
$list = $('#planning_applications'),
Expand Down
10 changes: 0 additions & 10 deletions test/unit/financial_transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,6 @@ class FinancialTransactionTest < ActiveSupport::TestCase
@financial_transaction.destroy
end
end

context "when returning full_table_count" do
setup do
3.times {Factory(:financial_transaction)}
end

should "return count of all records" do
assert_equal FinancialTransaction.count, FinancialTransaction.full_table_count
end
end
end

context 'an instance of the FinancialTransaction class' do
Expand Down
2 changes: 1 addition & 1 deletion vendor/plugins/geokit-rails/test/acts_as_mappable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def test_find_within_bounds
end

def test_find_within_bounds_ordered_by_distance
locations = Location.find_within_bounds([@sw,@ne], :origin=>@bounds_center, :order=>'distance asc')
locations = Location.find_within_bounds([@sw,@ne], :origin=>@bounds_center, :order=>'distance ASC')
assert_equal locations[0], locations(:d)
assert_equal locations[1], locations(:a)
end
Expand Down

0 comments on commit 05b2455

Please sign in to comment.