From cb1fce21ba4f8c7926f58f2d4c53047e1396b4e4 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Wed, 19 Jun 2019 12:27:19 +0200 Subject: [PATCH 1/2] hydra-server: set a limit on builds and buildoutputs search This patch adds a limit statement for Postgresql queries on `builds` and `buildsoutputs` tables. --- src/lib/Hydra/Controller/Root.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 41f6305c..796c4b6f 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -423,11 +423,15 @@ sub search :Local Args(0) { # Perform build search in separate queries to prevent seq scan on buildoutputs table. $c->stash->{builds} = [ $c->model('DB::Builds')->search( { "buildoutputs.path" => { ilike => "%$query%" } }, - { order_by => ["id desc"], join => ["buildoutputs"] } ) ]; + { order_by => ["id desc"], join => ["buildoutputs"] + , rows => $c->stash->{limit} + } ) ]; $c->stash->{buildsdrv} = [ $c->model('DB::Builds')->search( { "drvpath" => { ilike => "%$query%" } }, - { order_by => ["id desc"] } ) ]; + { order_by => ["id desc"] + , rows => $c->stash->{limit} + } ) ]; $c->stash->{resource} = { projects => $c->stash->{projects}, jobsets => $c->stash->{jobsets}, From d1e590af1f4cb131e5de0c7cf2fa7d855a2ae15c Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Wed, 19 Jun 2019 12:33:25 +0200 Subject: [PATCH 2/2] hydra-server: add `limit` parameter to the `search` path This allows a client to set a limit to the search results it wants to get: http://hydra.nixos.org/search?query=emacs&limit=1 This returns only 1 results (while the default is 500). --- src/lib/Hydra/Controller/Root.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 796c4b6f..188d73bd 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -391,7 +391,12 @@ sub search :Local Args(0) { error($c, "Invalid character in query.") unless $query =~ /^[a-zA-Z0-9_\-\/.]+$/; - $c->stash->{limit} = 500; + my $limit = trim $c->request->params->{"limit"}; + if ($limit eq "") { + $c->stash->{limit} = 500; + } else { + $c->stash->{limit} = $limit; + } $c->stash->{projects} = [ $c->model('DB::Projects')->search( { -and =>