Query all testboxes from es, and return a non repetitive list
Signed-off-by: Li Yuanchao <lyc163mail(a)163.com>
---
src/lib/web_backend.rb | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb
index e548d61..a897b57 100644
--- a/src/lib/web_backend.rb
+++ b/src/lib/web_backend.rb
@@ -435,3 +435,31 @@ def template_body(request_body)
formatter = FormatEchartData.new(compare_results, request_body)
formatter.format_for_echart.to_json
end
+
+def search_testboxes
+ query = { size: 0, aggs: { testboxes: { terms: { size: 10000, field: 'testbox' } } } }
+ buckets = es_query(query)['aggregations']['testboxes']['buckets']
+ testboxes = []
+ buckets.each_index do |index|
+ testboxes[index] = buckets[index]['key']
+ end
+ return testboxes, testboxes.length
+end
+
+def testboxes_body
+ testboxes, total = search_testboxes
+ {
+ total: total,
+ testboxes: testboxes
+ }.to_json
+end
+
+def query_testboxes
+ begin
+ body = testboxes_body
+ rescue StandardError => e
+ warn e.message
+ return [500, headers.merge('Access-Control-Allow-Origin' => '*'), 'get repos error']
+ end
+ [200, headers.merge('Access-Control-Allow-Origin' => '*'), body]
+end
--
2.23.0