From 7a09b2142cccbf3019986294442a7278cad135bb Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Fri, 26 Feb 2010 12:54:51 +0000 Subject: Add SP version to memcache key --- diff --git a/site/app/config/core.php b/site/app/config/core.php index 2afbc0e..8e9c0d5 100644 --- a/site/app/config/core.php +++ b/site/app/config/core.php @@ -219,4 +219,20 @@ function n___($message, $message_plural, $num, $context ="") { return ngettext($message, $message_plural, $num); } } + +if (!function_exists('parse_sp')) { + function parse_sp() { + if (preg_match('/OLPC\/0\.([^-]*)-/', env('HTTP_USER_AGENT'), $matches)) { + if (floatval($matches[1]) <= 4.6) + return '0.82'; + else + return '0.84'; + } else { + if (preg_match('/Sugar Labs\/([0-9]+)\.([0-9]+)/', env('HTTP_USER_AGENT'), $matches)) + return $matches[1].'.'.$matches[2]; + else + return SITE_SUGAR_STABLE; + } + } +} ?> diff --git a/site/app/models/addon.php b/site/app/models/addon.php index cf533d2..1b55f9d 100644 --- a/site/app/models/addon.php +++ b/site/app/models/addon.php @@ -180,8 +180,11 @@ class Addon extends AppModel function getAddon($id, $associations = array(), $app_ver = null) { global $valid_status; + if (!isset($app_ver) || $app_ver == 'any') + $app_ver = parse_sp(); + // if this object is cached, grab it from memcache - $identifier = array("addon:$id", $associations); + $identifier = array("addon:$id", $associations, $app_ver); if (QUERY_CACHE && $cached = $this->Cache->readCacheObject($identifier)) { if (DEBUG >= 2) debug("addon $id was cached"); return $cached; @@ -377,7 +380,7 @@ class Addon extends AppModel ORDER BY score DESC LIMIT 5"); $addon['Recommendations'] = array(); foreach ($rec_ids as $r) { - $addon['Recommendations'][] = $this->getAddon($r['recs']['id']); + $addon['Recommendations'][] = $this->getAddon($r['recs']['id'], $app_ver); } } diff --git a/site/app/models/file.php b/site/app/models/file.php index 1041f5d..dc02aaa 100644 --- a/site/app/models/file.php +++ b/site/app/models/file.php @@ -85,18 +85,7 @@ class File extends AppModel function getLatestFileByAddonId($addon_id, $platform_id = null) { // Platform WHERE if necessary $platform = !empty($platform_id) ? " AND (File.platform_id = ".PLATFORM_ALL." OR File.platform_id = {$platform_id})" : ''; - - if (preg_match('/OLPC\/0\.([^-]*)-/', env('HTTP_USER_AGENT'), $matches)) { - if (floatval($matches[1]) <= 4.6) - $sp = '0.82'; - else - $sp = '0.84'; - } else { - if (preg_match('/Sugar Labs\/([0-9]+)\.([0-9]+)/', env('HTTP_USER_AGENT'), $matches)) - $sp = $matches[1].'.'.$matches[2]; - else - $sp = SITE_SUGAR_STABLE; - } + $sp = parse_sp(); $sql = " SELECT diff --git a/site/app/models/version.php b/site/app/models/version.php index 396124f..c0ea46d 100644 --- a/site/app/models/version.php +++ b/site/app/models/version.php @@ -137,21 +137,8 @@ class Version extends AppModel if (!is_array($status)) $status = array($status); $status_sql = implode(',',$status); - if (isset($app_ver) && $app_ver != 'any') - $sp = $app_ver; - else { - if (preg_match('/OLPC\/0\.([^-]*)-/', env('HTTP_USER_AGENT'), $matches)) { - if (floatval($matches[1]) <= 4.6) - $sp = '0.82'; - else - $sp = '0.84'; - } else { - if (preg_match('/Sugar Labs\/([0-9]+)\.([0-9]+)/', env('HTTP_USER_AGENT'), $matches)) - $sp = $matches[1].'.'.$matches[2]; - else - $sp = SITE_SUGAR_STABLE; - } - } + if (!isset($app_ver) || $app_ver == 'any') + $app_ver = parse_sp(); $sql = " SELECT @@ -169,7 +156,7 @@ class Version extends AppModel WHERE Version.addon_id = {$id} ORDER BY - IF({$sp} AND ({$sp} < CAST(B.version AS DECIMAL(3,3)) OR {$sp} > CAST(C.version AS DECIMAL(3,3))), 1, 1000000) + CAST(Version.version AS DECIMAL) DESC + IF({$app_ver} AND ({$app_ver} < CAST(B.version AS DECIMAL(3,3)) OR {$app_ver} > CAST(C.version AS DECIMAL(3,3))), 1, 1000000) + CAST(Version.version AS DECIMAL) DESC LIMIT 1 "; -- cgit v0.9.1