diff options
author | Lukas Fleischer <lfleischer@archlinux.org> | 2019-10-07 00:00:41 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2019-10-07 15:31:18 +0200 |
commit | f804ea4abb8001ddcc2cbc5bbb59d5f85c68b737 (patch) | |
tree | 777e0699b2fa7878cf2d57ce2a959853dc23e7f8 /web | |
parent | 6493d00db5358e6b52c7b3b5896f99ebd9c43d8c (diff) | |
download | aur-f804ea4abb8001ddcc2cbc5bbb59d5f85c68b737.tar.gz aur-f804ea4abb8001ddcc2cbc5bbb59d5f85c68b737.tar.xz |
Cache package licenses, groups and relations
Cache more package details if the global caching mechanism is enabled.
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'web')
-rw-r--r-- | web/lib/pkgfuncs.inc.php | 66 |
1 files changed, 22 insertions, 44 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 3e4b2a8f..be4bb065 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -158,22 +158,15 @@ function pkg_from_name($name="") { * @return array All licenses for the package */ function pkg_licenses($pkgid) { - $lics = array(); $pkgid = intval($pkgid); - if ($pkgid > 0) { - $dbh = DB::connect(); - $q = "SELECT l.Name FROM Licenses l "; - $q.= "INNER JOIN PackageLicenses pl ON pl.LicenseID = l.ID "; - $q.= "WHERE pl.PackageID = ". $pkgid; - $result = $dbh->query($q); - if (!$result) { - return array(); - } - while ($row = $result->fetch(PDO::FETCH_COLUMN, 0)) { - $lics[] = $row; - } + if (!$pkgid) { + return array(); } - return $lics; + $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); + return array_map(function ($x) { return $x[0]; }, $rows); } /** @@ -184,22 +177,15 @@ function pkg_licenses($pkgid) { * @return array All package groups for the package */ function pkg_groups($pkgid) { - $grps = array(); $pkgid = intval($pkgid); - if ($pkgid > 0) { - $dbh = DB::connect(); - $q = "SELECT g.Name FROM `Groups` g "; - $q.= "INNER JOIN PackageGroups pg ON pg.GroupID = g.ID "; - $q.= "WHERE pg.PackageID = ". $pkgid; - $result = $dbh->query($q); - if (!$result) { - return array(); - } - while ($row = $result->fetch(PDO::FETCH_COLUMN, 0)) { - $grps[] = $row; - } + if (!$pkgid) { + return array(); } - return $grps; + $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); + return array_map(function ($x) { return $x[0]; }, $rows); } /** @@ -256,24 +242,16 @@ function pkg_dependencies($pkgid, $limit) { * @return array All package relations for the package */ function pkg_relations($pkgid) { - $rels = array(); $pkgid = intval($pkgid); - if ($pkgid > 0) { - $dbh = DB::connect(); - $q = "SELECT pr.RelName, rt.Name, pr.RelCondition, pr.RelArch, p.ID FROM PackageRelations pr "; - $q.= "LEFT JOIN Packages p ON pr.RelName = p.Name "; - $q.= "LEFT JOIN RelationTypes rt ON rt.ID = pr.RelTypeID "; - $q.= "WHERE pr.PackageID = ". $pkgid . " "; - $q.= "ORDER BY pr.RelName"; - $result = $dbh->query($q); - if (!$result) { - return array(); - } - while ($row = $result->fetch(PDO::FETCH_NUM)) { - $rels[] = $row; - } + if (!$pkgid) { + return array(); } - return $rels; + $q = "SELECT pr.RelName, rt.Name, pr.RelCondition, pr.RelArch, p.ID FROM PackageRelations pr "; + $q.= "LEFT JOIN Packages p ON pr.RelName = p.Name "; + $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); } /** |