On Tue, 12 Apr 2011 00:15:49 -0500
Dan McGee <[email protected]> wrote:
> The majority of "real world" info requests [1] come in hefty batches.
> We would be better served to handle these in one request rather than
> multiple by allowing AUR clients to send multiple arguments.
>
Hi, similarly, for AUR helpers, it could be a good thing to
provide maintainer information for both "search" and "info" methods to
avoid fetching the package's page just after querying info with rpc.
The attached patch is based on Dan's working branch.
>From d7d06859ddc9425930e586a0685f09f9798dfddc Mon Sep 17 00:00:00 2001
From: tuxce <[email protected]>
Date: Tue, 12 Apr 2011 12:42:30 +0200
Subject: [PATCH] rpc: unify methods return.
Include maintainer in info and search method.
---
web/lib/aurjson.class.php | 20 ++++++++------------
1 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 57096d8..3283a92 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -82,6 +82,11 @@ class AurJSON {
}
private function process_query($type, $query) {
+ $fields = implode(',', self::$fields);
+ $query = "SELECT Users.Username as Maintainer, {$fields} " .
+ " FROM Packages LEFT JOIN Users " .
+ " on Packages.MaintainerUID = Users.ID " .
+ " WHERE ${query}";
$result = db_query($query, $this->dbh);
if ( $result && (mysql_num_rows($result) > 0) ) {
@@ -140,13 +145,10 @@ class AurJSON {
return $this->json_error('Query arg too small');
}
- $fields = implode(',', self::$fields);
$keyword_string = mysql_real_escape_string($keyword_string, $this->dbh);
$keyword_string = addcslashes($keyword_string, '%_');
- $query = "SELECT {$fields} " .
- " FROM Packages WHERE " .
- " ( Name LIKE '%{$keyword_string}%' OR " .
+ $query = " ( Name LIKE '%{$keyword_string}%' OR " .
" Description LIKE '%{$keyword_string}%' )";
return $this->process_query('search', $query);
@@ -158,7 +160,6 @@ class AurJSON {
* @return mixed Returns an array of value data containing the package data
**/
private function info($pqdata) {
- $fields = implode(',', self::$fields);
$args = $this->parse_info_args($pqdata);
$ids = $args['ids'];
$names = $args['names'];
@@ -167,8 +168,7 @@ class AurJSON {
return $this->json_error('Invalid query arguments');
}
- $query = "SELECT {$fields} " .
- " FROM Packages WHERE ";
+ $query = "";
if ($ids) {
$ids_value = implode(',', $args['ids']);
$query .= "ID IN ({$ids_value})";
@@ -191,13 +191,9 @@ class AurJSON {
* @return mixed Returns an array of value data containing the package data
**/
private function msearch($maintainer) {
- $fields = implode(',', self::$fields);
$maintainer = mysql_real_escape_string($maintainer, $this->dbh);
- $query = "SELECT Users.Username as Maintainer, {$fields} " .
- " FROM Packages, Users WHERE " .
- " Packages.MaintainerUID = Users.ID AND " .
- " Users.Username = '{$maintainer}'";
+ $query = " Users.Username = '{$maintainer}'";
return $this->process_query('msearch', $query);
}
--
1.7.4.4