summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2019-10-06 19:36:09 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2019-10-06 22:13:38 +0200
commit6493d00db5358e6b52c7b3b5896f99ebd9c43d8c (patch)
tree663c253408e0b00bf90286180a28637acb0e0120
parent1283fe4918adb369432ea2acc378610a3d5142a9 (diff)
downloadaur-6493d00db5358e6b52c7b3b5896f99ebd9c43d8c.tar.gz
aur-6493d00db5358e6b52c7b3b5896f99ebd9c43d8c.tar.xz
aurjson: cache extended fields
Cache the results of the extended fields computation if the global caching mechanism is enabled. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
-rw-r--r--web/lib/aurjson.class.php17
1 files changed, 4 insertions, 13 deletions
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index c275d214..bfb8cd14 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -292,11 +292,7 @@ class AurJSON {
"FROM Licenses INNER JOIN PackageLicenses " .
"ON PackageLicenses.PackageID = " . $pkgid . " " .
"AND PackageLicenses.LicenseID = Licenses.ID";
- $result = $this->dbh->query($query);
-
- if (!$result) {
- return null;
- }
+ $rows = db_cache_result($query, 'extended-fields:' . $pkgid, PDO::FETCH_ASSOC);
$type_map = array(
'depends' => 'Depends',
@@ -310,7 +306,7 @@ class AurJSON {
'license' => 'License',
);
$data = array();
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($rows as $row) {
$type = $type_map[$row['Type']];
$data[$type][] = $row['Name'] . $row['Cond'];
}
@@ -319,13 +315,8 @@ class AurJSON {
$query = "SELECT Keyword FROM PackageKeywords " .
"WHERE PackageBaseID = " . intval($base_id) . " " .
"ORDER BY Keyword ASC";
- $result = $this->dbh->query($query);
-
- if (!$result) {
- return null;
- }
-
- $data['Keywords'] = $result->fetchAll(PDO::FETCH_COLUMN, 0);
+ $rows = db_cache_result($query, 'keywords:' . intval($base_id));
+ $data['Keywords'] = array_map(function ($x) { return $x[0]; }, $rows);
}
return $data;