diff options
author | Lukas Fleischer <lfleischer@archlinux.org> | 2019-10-07 18:19:20 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2019-10-07 18:21:03 +0200 |
commit | 734527370d1074edc2d9eadf191a6bc28fcd3dc2 (patch) | |
tree | e4a71fef80ff6928282fcd2439e3dace96726368 | |
parent | f804ea4abb8001ddcc2cbc5bbb59d5f85c68b737 (diff) | |
download | aur-734527370d1074edc2d9eadf191a6bc28fcd3dc2.tar.gz aur-734527370d1074edc2d9eadf191a6bc28fcd3dc2.tar.xz |
Make package details cache TTL configurable
The TTL for package details can be much longer than for generic values
since they never change. Note that when an update is pushed via Git, all
packages belonging to that package base are deleted and new packages are
created.
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
-rw-r--r-- | conf/config.defaults | 1 | ||||
-rw-r--r-- | web/lib/aurjson.class.php | 6 | ||||
-rw-r--r-- | web/lib/pkgfuncs.inc.php | 15 |
3 files changed, 15 insertions, 7 deletions
diff --git a/conf/config.defaults b/conf/config.defaults index c8bc3a7e..c519eae6 100644 --- a/conf/config.defaults +++ b/conf/config.defaults @@ -38,6 +38,7 @@ render-comment-cmd = /usr/local/bin/aurweb-rendercomment localedir = /srv/http/aurweb/aur.git/web/locale/ # memcache or apc cache = none +cache_pkginfo_ttl = 86400 memcache_servers = 127.0.0.1:11211 [ratelimit] diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php index bfb8cd14..1c31a65e 100644 --- a/web/lib/aurjson.class.php +++ b/web/lib/aurjson.class.php @@ -292,7 +292,8 @@ class AurJSON { "FROM Licenses INNER JOIN PackageLicenses " . "ON PackageLicenses.PackageID = " . $pkgid . " " . "AND PackageLicenses.LicenseID = Licenses.ID"; - $rows = db_cache_result($query, 'extended-fields:' . $pkgid, PDO::FETCH_ASSOC); + $ttl = config_get_int('options', 'cache_pkginfo_ttl'); + $rows = db_cache_result($query, 'extended-fields:' . $pkgid, PDO::FETCH_ASSOC, $ttl); $type_map = array( 'depends' => 'Depends', @@ -315,7 +316,8 @@ class AurJSON { $query = "SELECT Keyword FROM PackageKeywords " . "WHERE PackageBaseID = " . intval($base_id) . " " . "ORDER BY Keyword ASC"; - $rows = db_cache_result($query, 'keywords:' . intval($base_id)); + $ttl = config_get_int('options', 'cache_pkginfo_ttl'); + $rows = db_cache_result($query, 'keywords:' . intval($base_id), PDO::FETCH_NUM, $ttl); $data['Keywords'] = array_map(function ($x) { return $x[0]; }, $rows); } diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index be4bb065..b5035dfc 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -165,7 +165,8 @@ function pkg_licenses($pkgid) { $q = "SELECT l.Name FROM Licenses l "; $q.= "INNER JOIN PackageLicenses pl ON pl.LicenseID = l.ID "; $q.= "WHERE pl.PackageID = ". $pkgid; - $rows = db_cache_result($q, 'licenses:' . $pkgid); + $ttl = config_get_int('options', 'cache_pkginfo_ttl'); + $rows = db_cache_result($q, 'licenses:' . $pkgid, PDO::FETCH_NUM, $ttl); return array_map(function ($x) { return $x[0]; }, $rows); } @@ -184,7 +185,8 @@ function pkg_groups($pkgid) { $q = "SELECT g.Name FROM `Groups` g "; $q.= "INNER JOIN PackageGroups pg ON pg.GroupID = g.ID "; $q.= "WHERE pg.PackageID = ". $pkgid; - $rows = db_cache_result($q, 'groups:' . $pkgid); + $ttl = config_get_int('options', 'cache_pkginfo_ttl'); + $rows = db_cache_result($q, 'groups:' . $pkgid, PDO::FETCH_NUM, $ttl); return array_map(function ($x) { return $x[0]; }, $rows); } @@ -208,7 +210,8 @@ function pkg_providers($name) { $q.= "UNION "; $q.= "SELECT 0, Name FROM OfficialProviders "; $q.= "WHERE Provides = " . $dbh->quote($name); - return db_cache_result($q, 'providers:' . $name); + $ttl = config_get_int('options', 'cache_pkginfo_ttl'); + return db_cache_result($q, 'providers:' . $name, PDO::FETCH_NUM, $ttl); } /** @@ -231,7 +234,8 @@ function pkg_dependencies($pkgid, $limit) { $q.= "LEFT JOIN DependencyTypes dt ON dt.ID = pd.DepTypeID "; $q.= "WHERE pd.PackageID = ". $pkgid . " "; $q.= "ORDER BY pd.DepName LIMIT " . intval($limit); - return db_cache_result($q, 'dependencies:' . $pkgid); + $ttl = config_get_int('options', 'cache_pkginfo_ttl'); + return db_cache_result($q, 'dependencies:' . $pkgid, PDO::FETCH_NUM, $ttl); } /** @@ -251,7 +255,8 @@ function pkg_relations($pkgid) { $q.= "LEFT JOIN RelationTypes rt ON rt.ID = pr.RelTypeID "; $q.= "WHERE pr.PackageID = ". $pkgid . " "; $q.= "ORDER BY pr.RelName"; - return db_cache_result($q, 'relations:' . $pkgid); + $ttl = config_get_int('options', 'cache_pkginfo_ttl'); + return db_cache_result($q, 'relations:' . $pkgid, PDO::FETCH_NUM, $ttl); } /** |