summaryrefslogtreecommitdiffstats
path: root/web/lib/pkgfuncs.inc.php
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2019-10-06 18:59:34 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2019-10-06 22:13:38 +0200
commit1283fe4918adb369432ea2acc378610a3d5142a9 (patch)
tree51e99ed1cccae85823213049fe81a9ab00e43a76 /web/lib/pkgfuncs.inc.php
parentef8bad5bbfa208daf3496dccd16c14577ba5607b (diff)
downloadaur-1283fe4918adb369432ea2acc378610a3d5142a9.tar.gz
aur-1283fe4918adb369432ea2acc378610a3d5142a9.tar.xz
Cache package provider and dependency information
The package provider and dependency queries are quite CPU-intensive and usually yield rather small result sets. Cache these values if the global caching mechanism is enabled. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'web/lib/pkgfuncs.inc.php')
-rw-r--r--web/lib/pkgfuncs.inc.php40
1 files changed, 11 insertions, 29 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index 00f0cc45..3e4b2a8f 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -222,17 +222,7 @@ function pkg_providers($name) {
$q.= "UNION ";
$q.= "SELECT 0, Name FROM OfficialProviders ";
$q.= "WHERE Provides = " . $dbh->quote($name);
- $result = $dbh->query($q);
-
- if (!$result) {
- return array();
- }
-
- $providers = array();
- while ($row = $result->fetch(PDO::FETCH_NUM)) {
- $providers[] = $row;
- }
- return $providers;
+ return db_cache_result($q, 'providers:' . $name);
}
/**
@@ -244,26 +234,18 @@ function pkg_providers($name) {
* @return array All package dependencies for the package
*/
function pkg_dependencies($pkgid, $limit) {
- $deps = array();
$pkgid = intval($pkgid);
- if ($pkgid > 0) {
- $dbh = DB::connect();
- $q = "SELECT pd.DepName, dt.Name, pd.DepDesc, ";
- $q.= "pd.DepCondition, pd.DepArch, p.ID ";
- $q.= "FROM PackageDepends pd ";
- $q.= "LEFT JOIN Packages p ON pd.DepName = p.Name ";
- $q.= "LEFT JOIN DependencyTypes dt ON dt.ID = pd.DepTypeID ";
- $q.= "WHERE pd.PackageID = ". $pkgid . " ";
- $q.= "ORDER BY pd.DepName LIMIT " . intval($limit);
- $result = $dbh->query($q);
- if (!$result) {
- return array();
- }
- while ($row = $result->fetch(PDO::FETCH_NUM)) {
- $deps[] = $row;
- }
+ if (!$pkgid) {
+ return array();
}
- return $deps;
+ $q = "SELECT pd.DepName, dt.Name, pd.DepDesc, ";
+ $q.= "pd.DepCondition, pd.DepArch, p.ID ";
+ $q.= "FROM PackageDepends pd ";
+ $q.= "LEFT JOIN Packages p ON pd.DepName = p.Name ";
+ $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);
}
/**