Added cached_votes_score #24

Merged
merged 1 commit into from Jan 18, 2013

Projects

None yet

4 participants

@elado
Contributor
elado commented Dec 26, 2012

Added cached_votes_score, which calculates upvotes - downvotes, for the ability to sort by good votes.

@ryanto
Owner
ryanto commented Dec 29, 2012

I think this is a good idea, but does it need to be stored in the db? Couldn't you just a method cached_votes_score which does upvotes - downvotes on the fly?

@elado
Contributor
elado commented Dec 29, 2012

If you order by cached_votes_up - cached_votes_down DESC (to get the highest rated items) it won't use the DB index which is extremely important on large data-sets.

I don't think cached_votes_total is really useful, it's not telling anything about popularity (because most votes might be downvotes).

@twelvelabs

+1.

@elado
Contributor
elado commented Jan 18, 2013

And like all cache fields, it doesn't affect performance unless the column exists. It also reuses values from cached_votes_up/down instead of refetching, so it's pretty efficient.

@ryanto ryanto merged commit 580c2b2 into ryanto:master Jan 18, 2013
@ryanto
Owner
ryanto commented Jan 18, 2013

Thanks, I'll push this to rubygems this weekend.

@turkungucu

When will you push this to rubygems? Thanks :)

@elado
Contributor
elado commented Jan 21, 2013

@turkungucu meanwhile you can use

gem 'acts_as_votable', github: 'ryanto/acts_as_votable'

but be sure to track changes on master.

@turkungucu

will do! thanks a lot.

@ryanto
Owner
ryanto commented Jan 22, 2013
gem 'acts_as_votable', '~> 0.5.0'

Please make sure your database is up to date. The lastest batch or PRs changed the migration. See the columns that are needed in: https://github.com/ryanto/acts_as_votable/blob/master/lib/generators/acts_as_votable/migration/templates/active_record/migration.rb

@turkungucu

Thanks. I noticed voted_for? is replaced with voted_on?

Can you confirm? You might want to update the readme :)

@ryanto
Owner
ryanto commented Jan 22, 2013

Nice find, someone did some alias shuffling in one of the commits and must have removed this. I'll add it back tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment