From 59798360066ad341534fcd77b5fefb5adc52b6e6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 14 May 2009 04:05:14 +0000 Subject: Change the way we update view_count to use math instead of ORM for better accuracy --- core/controllers/albums.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'core') 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; } -- cgit v1.2.3