summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdocs/CHANGELOG1
-rw-r--r--lib/class/browse.class.php8
-rw-r--r--lib/class/rating.class.php36
-rw-r--r--lib/class/vauth.class.php3
-rw-r--r--templates/show_albums.inc.php3
5 files changed, 40 insertions, 11 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 3385228c..b323dead 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,7 @@
--------------------------------------------------------------------------
v.3.5-Alpha1
+ - Fixed rating caching so it actually completely works now
- Removed redundent UPDATE on session table due to /util.php
- Added Batch Download to single Artist view
- Added back in the direct links on songs, requires download set
diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php
index 663761fd..932b4064 100644
--- a/lib/class/browse.class.php
+++ b/lib/class/browse.class.php
@@ -825,19 +825,16 @@ class Browse {
switch ($_SESSION['browse']['type']) {
case 'song':
show_box_top(_('Songs') . $match, $class);
+ Song::build_cache($object_ids);
require_once Config::get('prefix') . '/templates/show_songs.inc.php';
show_box_bottom();
break;
case 'album':
show_box_top(_('Albums') . $match, $class);
+ Album::build_cache($object_ids);
require_once Config::get('prefix') . '/templates/show_albums.inc.php';
show_box_bottom();
break;
- case 'genre':
- show_box_top(_('Genres') . $match, $class);
- require_once Config::get('prefix') . '/templates/show_genres.inc.php';
- show_box_bottom();
- break;
case 'user':
show_box_top(_('Manage Users') . $match, $class);
require_once Config::get('prefix') . '/templates/show_users.inc.php';
@@ -845,6 +842,7 @@ class Browse {
break;
case 'artist':
show_box_top(_('Artists') . $match, $class);
+ Artist::build_cache($object_ids);
require_once Config::get('prefix') . '/templates/show_artists.inc.php';
show_box_bottom();
break;
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php
index 3f317187..6d89b8fb 100644
--- a/lib/class/rating.class.php
+++ b/lib/class/rating.class.php
@@ -73,11 +73,30 @@ class Rating extends database_object {
$db_results = Dba::query($sql);
while ($row = Dba::fetch_assoc($db_results)) {
- $results[$row['object_id']] = intval($row['rating']);
+ $user[$row['object_id']] = $row['rating'];
}
+ $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'";
+ $db_results = Dba::query($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $rating[$row['object_id']]['rating'] += $row['rating'];
+ $rating[$row['object_id']]['total']++;
+ }
+
foreach ($ids as $id) {
- parent::add_to_cache('rating_' . $type . '_user',$id,intval($results[$id]));
+ parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id]));
+
+ // Do the bit of math required to store this
+ if (!isset($rating[$id])) {
+ $entry = array('average'=>'0','percise'=>'0');
+ }
+ else {
+ $average = round($rating[$id]['rating']/$rating[$id]['total'],1);
+ $entry = array('average'=>floor($average),'percise'=>$average);
+ }
+
+ parent::add_to_cache('rating_' . $type . '_all',$id,$entry);
}
return true;
@@ -91,6 +110,8 @@ class Rating extends database_object {
*/
public function get_user($user_id) {
+ $id = intval($this->id);
+
if (parent::is_cached('rating_' . $this->type . '_user',$id)) {
return parent::get_from_cache('rating_' . $this->type . '_user',$id);
}
@@ -117,7 +138,16 @@ class Rating extends database_object {
*/
public function get_average() {
- $sql = "SELECT `rating` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type'";
+ $id = intval($this->id);
+
+ if (parent::is_cached('rating_' . $this->type . '_all',$id)) {
+ $data = parent::get_from_cache('rating_' . $this->type . '_user',$id);
+ $this->rating = $data['rating'];
+ $this->perciserating = $data['percise'];
+ return true;
+ }
+
+ $sql = "SELECT `rating` FROM `rating` WHERE `object_id`='$id' AND `object_type`='$this->type'";
$db_results = Dba::query($sql);
$i = 0;
diff --git a/lib/class/vauth.class.php b/lib/class/vauth.class.php
index 410b2155..c509b786 100644
--- a/lib/class/vauth.class.php
+++ b/lib/class/vauth.class.php
@@ -88,9 +88,6 @@ class vauth {
*/
public static function write($key,$value) {
- // If we'd set NO_SESSION never run this
- if (NO_SESSION == 1) { return true; }
-
$length = Config::get('session_length');
$value = Dba::escape($value);
$key = Dba::escape($key);
diff --git a/templates/show_albums.inc.php b/templates/show_albums.inc.php
index cea21087..8f1cccf5 100644
--- a/templates/show_albums.inc.php
+++ b/templates/show_albums.inc.php
@@ -48,6 +48,9 @@ $ajax_url = Config::get('ajax_url');
<th class="cel_action"><?php echo _('Actions'); ?></th>
</tr>
<?php
+ if (Config::get('ratings')) {
+ Rating::build_cache('album',$object_ids);
+ }
/* Foreach through the albums */
foreach ($object_ids as $album_id) {
$album = new Album($album_id);