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:
Lukas Fleischer 2015-09-18 08:02:33 +02:00
parent 0dd27a86b1
commit 9cae17ff7c
2 changed files with 14 additions and 49 deletions

View file

@ -479,42 +479,6 @@ function pkg_sources($pkgid) {
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
*