edgarjs/ajaxful-rating — pull request #60 by nathancolgate (2011-12-18 18:18:10+00:00)
Title: Unnecessary queries for star_tag

When a rateable object has :allow_update set to true, the star_tag method doesn't need to check to see if the object has already been rated.

I was seeing a lot of extraneous database calls when I was logged in, especially on my rateable#index page:

```
Rate Load (0.6ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 756 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 756 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 756 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 756 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 756 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
Rate Load (0.6ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 755 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 755 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 755 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 755 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 755 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
Rate Load (0.4ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 752 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 752 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 752 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 752 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 752 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
Rate Load (0.3ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 762 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 762 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 762 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 762 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 762 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT
Rate Load (0.4ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 754 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 754 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 754 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 754 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 754 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
Rate Load (0.4ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 753 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 753 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 753 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 753 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 753 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
Rate Load (0.6ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 763 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 763 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 763 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 763 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 763 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
Rate Load (0.4ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 751 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 751 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 751 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 751 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 751 AND "rates"."rateable_type" = 'Song' AND "rates"."dimension" = 'enjoyment' AND "rates"."rater_id" = 1 LIMIT 1

```

These calls totally make sense when we don't want users to update their ratings, but otherwise they're unnecessary.

Problem fixed by moving the :allow_update config check up.