Added cached_votes_total and cached_votes_down to Legislation Proposals

This commit is contained in:
María Checa
2017-10-25 16:42:24 +02:00
parent 231a14c428
commit b5f2f9aa21
3 changed files with 18 additions and 2 deletions

View File

@@ -80,10 +80,18 @@ class Legislation::Proposal < ActiveRecord::Base
/\A#{Setting["proposal_code_prefix"]}-\d\d\d\d-\d\d-(\d*)\z/.match(terms) /\A#{Setting["proposal_code_prefix"]}-\d\d\d\d-\d\d-(\d*)\z/.match(terms)
end end
def total_votes def likes
cached_votes_up cached_votes_up
end end
def dislikes
cached_votes_down
end
def total_votes
cached_votes_total
end
def voters def voters
User.active.where(id: votes_for.voters) User.active.where(id: votes_for.voters)
end end

View File

@@ -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

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -528,6 +528,8 @@ ActiveRecord::Schema.define(version: 20171020163240) do
t.integer "community_id" t.integer "community_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_down", default: 0
end end
add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree