[1/1] This patch implements FS#54906. Ability to query by pkgver via RPC or web request (url)

Message ID 20180607220922.2455-1-nodivbyzero@gmail.com
State New
Headers show
Series
  • [1/1] This patch implements FS#54906. Ability to query by pkgver via RPC or web request (url)
Related show

Commit Message

Nodiv Byzero June 7, 2018, 10:09 p.m. UTC
---
 web/lib/aurjson.class.php | 5 +++++
 web/lib/pkgfuncs.inc.php  | 4 ++++
 2 files changed, 9 insertions(+)

Comments

Lukas Fleischer June 9, 2018, 10:42 a.m. UTC | #1
On Fri, 08 Jun 2018 at 00:09:22, nodivbyzero wrote:
> ---
>  web/lib/aurjson.class.php | 5 +++++
>  web/lib/pkgfuncs.inc.php  | 4 ++++
>  2 files changed, 9 insertions(+)
> 

I don't quite understand what this is trying to fix. Can't the client
simply obtain the package without the package version and then compare
the versions itself? Please elaborate.

> diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
> index c51e9c2..30ce63f 100644
> --- a/web/lib/aurjson.class.php
> +++ b/web/lib/aurjson.class.php
> @@ -486,6 +486,11 @@ class AurJSON {
>  
>                         if ($search_by === 'name') {
>                                 $where_condition = "(Packages.Name LIKE $keyword_string)";
> +                               if (isset($http_data['pkgver'])) {
> +                                       $pkgver = $http_data['pkgver'];
> +                                       $pkgver_string = $this->dbh->quote($pkgver . "%");

Not sure how useful that would be. If we agree that this is something to
be implemented, I would expect to have proper support for version
comparisons as supported by pacman. When would be need to search by
matching prefixes?

Best regards.
Lukas
Nodiv Byzero June 10, 2018, 11:28 p.m. UTC | #2
Hey Lukas.

This patch implements additional check for package version. Of course,
all clients can search by the name and then compare the version
itself. But... this small improvement can help clients a lot. Here[1]
is the good example.

[1] https://github.com/falconindy/auracle/issues/3

On Sat, Jun 9, 2018 at 10:42 AM, Lukas Fleischer
<lfleischer@archlinux.org> wrote:
> On Fri, 08 Jun 2018 at 00:09:22, nodivbyzero wrote:
>> ---
>>  web/lib/aurjson.class.php | 5 +++++
>>  web/lib/pkgfuncs.inc.php  | 4 ++++
>>  2 files changed, 9 insertions(+)
>>
>
> I don't quite understand what this is trying to fix. Can't the client
> simply obtain the package without the package version and then compare
> the versions itself? Please elaborate.
>
>> diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
>> index c51e9c2..30ce63f 100644
>> --- a/web/lib/aurjson.class.php
>> +++ b/web/lib/aurjson.class.php
>> @@ -486,6 +486,11 @@ class AurJSON {
>>
>>                         if ($search_by === 'name') {
>>                                 $where_condition = "(Packages.Name LIKE $keyword_string)";
>> +                               if (isset($http_data['pkgver'])) {
>> +                                       $pkgver = $http_data['pkgver'];
>> +                                       $pkgver_string = $this->dbh->quote($pkgver . "%");
>
> Not sure how useful that would be. If we agree that this is something to
> be implemented, I would expect to have proper support for version
> comparisons as supported by pacman. When would be need to search by
> matching prefixes?
>
> Best regards.
> Lukas
Lukas Fleischer June 11, 2018, 2:54 p.m. UTC | #3
On Mon, 11 Jun 2018 at 01:28:36, Nodiv Byzero wrote:
> Hey Lukas.
> 
> This patch implements additional check for package version. Of course,
> all clients can search by the name and then compare the version
> itself. But... this small improvement can help clients a lot. Here[1]
> is the good example.

Looking at that GitHub issue, it seems like the prefix match would not
help here, though. We would need to implement proper version comparison
support.

I still do not see why this should be done as part of the search
request, though. The clients should have access to vercmp(8) or a proper
native version comparison implementation and adding a simple check after
retrieving the search results should be quite easy.

> 
> [1] https://github.com/falconindy/auracle/issues/3

Patch

diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index c51e9c2..30ce63f 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -486,6 +486,11 @@  class AurJSON {
 
 			if ($search_by === 'name') {
 				$where_condition = "(Packages.Name LIKE $keyword_string)";
+				if (isset($http_data['pkgver'])) {
+					$pkgver = $http_data['pkgver'];
+					$pkgver_string = $this->dbh->quote($pkgver . "%");
+					$where_condition .= " AND (Packages.Version LIKE $pkgver_string)";
+				}
 			} else if ($search_by === 'name-desc') {
 				$where_condition = "(Packages.Name LIKE $keyword_string OR ";
 				$where_condition .= "Description LIKE $keyword_string)";
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index ad25474..660e3f5 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -727,6 +727,10 @@  function pkg_search_page($params, $show_headers=true, $SID="") {
 			/* Search by name. */
 			$K = "%" . addcslashes($params['K'], '%_') . "%";
 			$q_where .= "AND (Packages.Name LIKE " . $dbh->quote($K) . ") ";
+			if (isset($params["pkgver"])) {
+				$pkgver = $params["pkgver"];
+				$q_where .= "AND (Packages.Version LIKE " . $dbh->quote($pkgver . "%") . ") ";
+			}
 		}
 		elseif (isset($params["SeB"]) && $params["SeB"] == "b") {
 			/* Search by package base name. */