[PATCH] [RFC] Allow to search packages by "*depends" fields

Baptiste Jonglez baptiste at bitsofnetworks.org
Sun Jan 28 00:20:55 UTC 2018


From: Baptiste Jonglez <git at bitsofnetworks.org>

It is now possible to search for packages that depend on a given package,
for instance:

    /rpc/?v=5&type=search&by=depends&arg=ocaml

It is also possible to match on "makedepends", "checkdepends" and
"optdepends".

Remaining tasks for a complete patch:

- actually test it...
- update documentation
- see if the additional SQL JOINs increase database load
- maybe add something like "by=anydepends" to match across all types of dependencies?

Signed-off-by: Baptiste Jonglez <git at bitsofnetworks.org>
---
 web/lib/aurjson.class.php | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 9eeaafd..addb92e 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -17,7 +17,8 @@ class AurJSON {
 		'suggest-pkgbase', 'get-comment-form'
 	);
 	private static $exposed_fields = array(
-		'name', 'name-desc', 'maintainer'
+		'name', 'name-desc', 'maintainer',
+		'depends', 'makedepends', 'checkdepends', 'optdepends'
 	);
 	private static $fields_v1 = array(
 		'Packages.ID', 'Packages.Name',
@@ -278,6 +279,10 @@ class AurJSON {
 				"ON PackageBases.ID = Packages.PackageBaseID " .
 				"LEFT JOIN Users " .
 				"ON PackageBases.MaintainerUID = Users.ID " .
+				"LEFT JOIN PackageDepends " .
+				"ON Packages.ID = PackageDepends.PackageID " .
+				"LEFT JOIN DependencyTypes " .
+				"ON PackageDepends.DepTypeID = DependencyTypes.ID " .
 				"WHERE ${where_condition} " .
 				"AND PackageBases.PackagerUID IS NOT NULL " .
 				"LIMIT $max_results";
@@ -407,6 +412,15 @@ class AurJSON {
 				$keyword_string = $this->dbh->quote($keyword_string);
 				$where_condition = "Users.Username = $keyword_string ";
 			}
+		} else if ($search_by === 'depends' || $search_by === 'makedepends' || $search_by === 'checkdepends' || $search_by === 'optdepends') {
+			if (empty($keyword_string)) {
+				return $this->json_error('Query arg is empty.');
+			} else {
+				$keyword_string = $this->dbh->quote($keyword_string);
+				$search_string = $this->dbh->quote($search_by);
+				$where_condition = "PackageDepends.DepName = $keyword_string AND ";
+				$where_condition .= "DependencyTypes.Name = $search_string";
+			}
 		}
 
 		return $this->process_query('search', $where_condition);
-- 
2.16.1


More information about the aur-dev mailing list