Skip to content
Snippets Groups Projects
Unverified Commit 930c2f31 authored by Mathieu Othacehe's avatar Mathieu Othacehe
Browse files

Do not allow full search on nix_name field.

Searching for something like "%a%" can take up to ten minutes. Remove the
usage of special characters "^" and "$" in queries. Instead, always add a "%"
character at the end of the query. Also add an index on the nix_name field.

Fixes: <https://issues.guix.gnu.org/43791>.

* src/sql/upgrade-13.sql: New file.
* Makefile.am (dist_sql_DATA): Add it.
* src/schema.sql (Builds_nix_name): New index.
* src/cuirass/database.scm (query->bind-arguments): Remove support for "^" and
"$" special characters. Instead make sure that the query does not contain any
"%" character and prefix the query by "%".
(db-get-builds-by-search): Remove an useless query nesting level.
* src/cuirass/templates.scm (search-form): Adapt the search help message
accordingly.
parent 71aac24f
No related branches found
No related tags found
No related merge requests found
......@@ -81,7 +81,8 @@ dist_sql_DATA = \
src/sql/upgrade-9.sql \
src/sql/upgrade-10.sql \
src/sql/upgrade-11.sql \
src/sql/upgrade-12.sql
src/sql/upgrade-12.sql \
src/sql/upgrade-13.sql
dist_css_DATA = \
src/static/css/cuirass.css \
......
......@@ -808,20 +808,13 @@ WHERE derivation =" derivation ";"))
`(#:status ,(assoc-ref status-values status)))
((_ invalid) '()) ; ignore
((query)
`(#:query
,(fold
(lambda (transform val)
(match transform
((pred modify-true modify-false)
((if (pred val) modify-true modify-false) val))))
query
;; Process special characters ^ and $.
(list (list (cut string-prefix? "^" <>)
(cut string-drop <> 1)
(cut string-append "%" <>))
(list (cut string-suffix? "$" <>)
(cut string-drop-right <> 1)
(cut string-append <> "%"))))))))
;; Remove any '%' that could make the search too slow and
;; add one at the end of the query.
`(#:query ,(string-append
(string-join
(string-split query #\%)
"")
"%")))))
(string-tokenize query-string))))
;; Normalize arguments
(fold (lambda (key acc)
......@@ -835,10 +828,9 @@ WHERE derivation =" derivation ";"))
FILTERS is an assoc list whose possible keys are the symbols query,
border-low-id, border-high-id, and nr."
(with-db-worker-thread db
(let* ((stmt-text (format #f "SELECT * FROM (
SELECT Builds.rowid, Builds.timestamp, Builds.starttime,
Builds.stoptime, Builds.log, Builds.status, Builds.job_name, Builds.system,
Builds.nix_name, Specifications.name
(let* ((stmt-text (format #f "SELECT Builds.rowid, Builds.timestamp,
Builds.starttime,Builds.stoptime, Builds.log, Builds.status,
Builds.job_name, Builds.system, Builds.nix_name, Specifications.name
FROM Builds
INNER JOIN Evaluations ON Builds.evaluation = Evaluations.id
INNER JOIN Specifications ON Evaluations.specification = Specifications.name
......@@ -857,8 +849,7 @@ ORDER BY
CASE WHEN :borderlowid IS NULL THEN Builds.rowid
ELSE -Builds.rowid
END DESC
LIMIT :nr)
ORDER BY rowid DESC;"))
LIMIT :nr;"))
(stmt (sqlite-prepare db stmt-text #:cache? #t)))
(apply sqlite-bind-arguments
stmt
......
......@@ -89,12 +89,10 @@
(code "failed-dependency") ", "
(code "failed-other") ", or "
(code "canceled") "."))
(p "You can also use the anchors " (code "^") " and " (code "$") "
for matching the beginning and the end of a name, respectively.")
(p "For example, the following query will list successful builds of
the " (code "guix-master") " specification for the " (code "i686-linux") "
system whose names start with " (code "guile-") ":" (br)
(code "spec:guix-master system:i686-linux status:success ^guile-")))))
(code "spec:guix-master system:i686-linux status:success guile-")))))
(define* (html-page title body navigation #:optional query)
"Return HTML page with given TITLE and BODY."
......
......@@ -98,6 +98,7 @@ CREATE TABLE Events (
-- Create indexes to speed up common queries.
CREATE INDEX Builds_status_index ON Builds (status);
CREATE INDEX Builds_evaluation_index ON Builds (evaluation, status);
CREATE INDEX Builds_nix_name ON Builds (nix_name COLLATE NOCASE);
CREATE INDEX Evaluations_status_index ON Evaluations (id, status);
CREATE INDEX Evaluations_specification_index ON Evaluations (specification, id DESC);
CREATE INDEX Outputs_derivation_index ON Outputs (derivation);
......
BEGIN TRANSACTION;
CREATE INDEX Builds_nix_name ON Builds (nix_name COLLATE NOCASE);
COMMIT;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment