summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-05-14 04:05:14 +0000
committerBharat Mediratta <bharat@menalto.com>2009-05-14 04:05:14 +0000
commit59798360066ad341534fcd77b5fefb5adc52b6e6 (patch)
tree20cfa8232f763da0efbce8694497be30f50e793d
parentd7fe3104e3566297b6a8ce2c5bfba0c6f7c41d72 (diff)
Change the way we update view_count to use math instead of ORM for better accuracy
-rw-r--r--core/controllers/albums.php6
1 files changed, 4 insertions, 2 deletions
diff --git a/core/controllers/albums.php b/core/controllers/albums.php
index adf9a282..41a7810d 100644
--- a/core/controllers/albums.php
+++ b/core/controllers/albums.php
@@ -65,8 +65,10 @@ class Albums_Controller extends Items_Controller {
$template->set_global("parents", $album->parents());
$template->content = new View("album.html");
- $album->view_count++;
- $album->save();
+ // We can't use math in ORM or the query builder, so do this by hand. It's important
+ // that we do this with math, otherwise concurrent accesses will damage accuracy.
+ Database::instance()->query(
+ "UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id");
print $template;
}