diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 5ced1529d..32badbb46 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -80,10 +80,18 @@ class Legislation::Proposal < ActiveRecord::Base /\A#{Setting["proposal_code_prefix"]}-\d\d\d\d-\d\d-(\d*)\z/.match(terms) end - def total_votes + def likes cached_votes_up end + def dislikes + cached_votes_down + end + + def total_votes + cached_votes_total + end + def voters User.active.where(id: votes_for.voters) end diff --git a/db/migrate/20171025142440_add_cached_votes_to_legislation_proposals.rb b/db/migrate/20171025142440_add_cached_votes_to_legislation_proposals.rb new file mode 100644 index 000000000..92544ddb6 --- /dev/null +++ b/db/migrate/20171025142440_add_cached_votes_to_legislation_proposals.rb @@ -0,0 +1,6 @@ +class AddCachedVotesToLegislationProposals < ActiveRecord::Migration + def change + add_column :legislation_proposals, :cached_votes_total, :integer, default: 0 + add_column :legislation_proposals, :cached_votes_down, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index f8dd19c13..05faf6f36 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171020163240) do +ActiveRecord::Schema.define(version: 20171025142440) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -528,6 +528,8 @@ ActiveRecord::Schema.define(version: 20171020163240) do t.integer "community_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "cached_votes_total", default: 0 + t.integer "cached_votes_down", default: 0 end add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree