Added cached_votes_score, which calculates upvotes - downvotes, for the ability to sort by good votes.
added cached_votes_score, which calculates upvotes - downvotes, for t…
…he ability to sort by good votes.
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?
upvotes - downvotes
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.
cached_votes_up - cached_votes_down DESC
I don't think cached_votes_total is really useful, it's not telling anything about popularity (because most votes might be downvotes).
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.
Thanks, I'll push this to rubygems this weekend.
When will you push this to rubygems? Thanks :)
@turkungucu meanwhile you can use
gem 'acts_as_votable', github: 'ryanto/acts_as_votable'
but be sure to track changes on master.
will do! thanks a lot.
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
Thanks. I noticed voted_for? is replaced with voted_on?
Can you confirm? You might want to update the readme :)
Nice find, someone did some alias shuffling in one of the commits and must have removed this. I'll add it back tonight.