# HG changeset patch # User Sascha L. Teichmann # Date 1552647892 -3600 # Node ID fe93c48f76c939838bfd6fc9c0a1894bb328d7a6 # Parent 43e1abaf9ee32283441790376b58037e1ec713c8 Add /api/imports?query=TXT to search TXT in kind, username, signer or logs. diff -r 43e1abaf9ee3 -r fe93c48f76c9 pkg/controllers/importqueue.go --- a/pkg/controllers/importqueue.go Fri Mar 15 10:18:49 2019 +0100 +++ b/pkg/controllers/importqueue.go Fri Mar 15 12:04:52 2019 +0100 @@ -163,25 +163,32 @@ a.stmt.WriteString(selectAfterSQL) b.stmt.WriteString(selectBeforeSQL) + cond := func(format string, v ...interface{}) { + l.cond(format, v...) + a.cond(format, v...) + b.cond(format, v...) + } + + if query := req.FormValue("query"); query != "" { + query = "%" + query + "%" + cond(` (kind ILIKE $%d OR username ILIKE $%d OR signer ILIKE $%d OR `+ + `id IN (SELECT import_id FROM import.import_logs WHERE msg ILIKE $%d)) `, + query, query, query, query) + } + if st := req.FormValue("states"); st != "" { states := toTextArray(st, imports.ImportStateNames) - l.cond(" state = ANY($%d) ", states) - a.cond(" state = ANY($%d) ", states) - b.cond(" state = ANY($%d) ", states) + cond(" state = ANY($%d) ", states) } if ks := req.FormValue("kinds"); ks != "" { kinds := toTextArray(ks, imports.ImportKindNames()) - l.cond(" kind = ANY($%d) ", kinds) - a.cond(" kind = ANY($%d) ", kinds) - b.cond(" kind = ANY($%d) ", kinds) + cond(" kind = ANY($%d) ", kinds) } if idss := req.FormValue("ids"); idss != "" { ids := toInt8Array(idss) - l.cond(" id = ANY($%d) ", ids) - a.cond(" id = ANY($%d) ", ids) - b.cond(" id = ANY($%d) ", ids) + cond(" id = ANY($%d) ", ids) } if from := req.FormValue("from"); from != "" { @@ -208,9 +215,7 @@ switch warn := strings.ToLower(req.FormValue("warnings")); warn { case "1", "t", "true": - l.cond(" id IN (SELECT id FROM warned) ") - a.cond(" id IN (SELECT id FROM warned) ") - b.cond(" id IN (SELECT id FROM warned) ") + cond(" id IN (SELECT id FROM warned) ") } if !l.hasCond { @@ -227,6 +232,8 @@ a.stmt.WriteString(" ORDER BY enqueued LIMIT 1") b.stmt.WriteString(" ORDER BY enqueued LIMIT 1") + log.Println(l.stmt.String()) + if noBefore { b = nil }