avoinministerio/avoinministerio — pull request #216 by jyrkive (2012-08-06 07:35:03+00:00)
Title: Reduce database hits caused by voting

In Pull Request #213, I switched the Idea#vote method to use a low-level update_column method to change the values of vote counters. That kept Idea#vote from changing the updated_at timestamp which was updated way too often.

Unfortunately, update_column can only change one column at a time and saves the changes immediately to the database. Therefore updating the vote counters requires currently four database hits. It may be a bad performance problem in the future, especially given that voting is by far the most common action.

The first of these commits reverts the changes I made in Pull Request #213, reducing the number of database hits in Idea#vote from four to one (75 % reduction! :). The second one introduces a new attribute, Idea#updated_content_at, whose value tracks when the idea content (heading, summary or the body) was updated last time. It does not track vote counter changes. In addition, I swithed the idea lists to display updated_content_at instead of updated_at.