mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Extract package name from details
When requesting package details, instead of performing another SQL query to obtain the package name, extract the name from the result of the package details query. Also, drop pkg_name_from_id() which is no longer needed after this optimization. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
0dd27a86b1
commit
9cae17ff7c
2 changed files with 14 additions and 49 deletions
|
@ -11,19 +11,25 @@ check_sid(); # see if they're still logged in
|
||||||
if (!isset($pkgid) || !isset($pkgname)) {
|
if (!isset($pkgid) || !isset($pkgname)) {
|
||||||
if (isset($_GET['ID'])) {
|
if (isset($_GET['ID'])) {
|
||||||
$pkgid = intval($_GET['ID']);
|
$pkgid = intval($_GET['ID']);
|
||||||
$pkgname = pkg_name_from_id($_GET['ID']);
|
|
||||||
} else if (isset($_GET['N'])) {
|
} else if (isset($_GET['N'])) {
|
||||||
$pkgid = pkg_from_name($_GET['N']);
|
$pkgid = pkg_from_name($_GET['N']);
|
||||||
$pkgname = $_GET['N'];
|
|
||||||
} else {
|
} else {
|
||||||
unset($pkgid, $pkgname);
|
unset($pkgid);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($pkgid) && ($pkgid == 0 || $pkgid == NULL || $pkgname == NULL)) {
|
$details = array();
|
||||||
|
if (isset($pkgid)) {
|
||||||
|
$details = pkg_get_details($pkgid);
|
||||||
|
$pkgname = $details['Name'];
|
||||||
|
} else {
|
||||||
|
unset($pkgname);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($pkgid) && ($pkgid == 0 || $pkgid == NULL || $pkgname == NULL)) {
|
||||||
header("HTTP/1.0 404 Not Found");
|
header("HTTP/1.0 404 Not Found");
|
||||||
include "./404.php";
|
include "./404.php";
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set the title to the current query or package name
|
# Set the title to the current query or package name
|
||||||
|
@ -35,11 +41,6 @@ if (isset($pkgname)) {
|
||||||
$title = __("Packages");
|
$title = __("Packages");
|
||||||
}
|
}
|
||||||
|
|
||||||
$details = array();
|
|
||||||
if (isset($pkgname)) {
|
|
||||||
$details = pkg_get_details($pkgid);
|
|
||||||
}
|
|
||||||
|
|
||||||
html_header($title, $details);
|
html_header($title, $details);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
|
@ -479,42 +479,6 @@ function pkg_sources($pkgid) {
|
||||||
return $sources;
|
return $sources;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine package names from package IDs
|
|
||||||
*
|
|
||||||
* @param string|array $pkgids The package IDs to get names for
|
|
||||||
*
|
|
||||||
* @return array|string All names if multiple package IDs, otherwise package name
|
|
||||||
*/
|
|
||||||
function pkg_name_from_id($pkgids) {
|
|
||||||
if (is_array($pkgids)) {
|
|
||||||
$pkgids = sanitize_ids($pkgids);
|
|
||||||
$names = array();
|
|
||||||
$dbh = DB::connect();
|
|
||||||
$q = "SELECT Name FROM Packages WHERE ID IN (";
|
|
||||||
$q.= implode(",", $pkgids) . ")";
|
|
||||||
$result = $dbh->query($q);
|
|
||||||
if ($result) {
|
|
||||||
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
|
||||||
$names[] = $row['Name'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $names;
|
|
||||||
}
|
|
||||||
elseif ($pkgids > 0) {
|
|
||||||
$dbh = DB::connect();
|
|
||||||
$q = "SELECT Name FROM Packages WHERE ID = " . $pkgids;
|
|
||||||
$result = $dbh->query($q);
|
|
||||||
if ($result) {
|
|
||||||
$name = $result->fetch(PDO::FETCH_NUM);
|
|
||||||
}
|
|
||||||
return $name[0];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the package details
|
* Get the package details
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue