[LNT] r312093 - v4_machine: Cleanup; NFC

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 19:11:38 PDT 2017


Author: matze
Date: Tue Aug 29 19:11:38 2017
New Revision: 312093

URL: http://llvm.org/viewvc/llvm-project?rev=312093&view=rev
Log:
v4_machine: Cleanup; NFC

Simplify code. Avoid database queries from jinja template.

Modified:
    lnt/trunk/lnt/server/ui/templates/v4_machine.html
    lnt/trunk/lnt/server/ui/views.py

Modified: lnt/trunk/lnt/server/ui/templates/v4_machine.html
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/templates/v4_machine.html?rev=312093&r1=312092&r2=312093&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/templates/v4_machine.html (original)
+++ lnt/trunk/lnt/server/ui/templates/v4_machine.html Tue Aug 29 19:11:38 2017
@@ -1,7 +1,5 @@
 {% import "utils.html" as utils %}
 {% import "local.html" as local %}
-{% set ts = request.get_testsuite() %}
-{% set machine = ts.getMachine(id) %}
 
 {% extends "layout.html" %}{
 {% set components = [(testsuite_name, v4_url_for(".v4_recent_activity"))] %}
@@ -18,7 +16,7 @@
   <h4>Relatives</h4>
   <ul class="nav nav-list bs-docs-sidenav">
     {# List all machines with this name. #}
-    {% for m in ts.machines(name=machine.name) %}
+    {% for m in relatives %}
     <li>{{ utils.render_machine(m) }}</li>
     {% endfor %}
   </ul>

Modified: lnt/trunk/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/views.py?rev=312093&r1=312092&r2=312093&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/views.py (original)
+++ lnt/trunk/lnt/server/ui/views.py Tue Aug 29 19:11:38 2017
@@ -293,18 +293,15 @@ def v4_machine(id):
     associated_runs = associated_runs.items()
     associated_runs.sort()
 
-    machines = ts.query(ts.Machine).all()
+    try:
+        machine = ts.query(ts.Machine).filter(ts.Machine.id == id).one()
+    except NoResultFound:
+        abort(404)
 
     if request.args.get('json'):
         json_obj = dict()
-        try:
-            machine_obj = ts.query(ts.Machine) \
-                .filter(ts.Machine.id == id) \
-                .one()
-        except NoResultFound:
-            abort(404)
-        json_obj['name'] = machine_obj.name
-        json_obj['id'] = machine_obj.id
+        json_obj['name'] = machine.name
+        json_obj['id'] = machine.id
         json_obj['runs'] = []
         for order in associated_runs:
             rev = order[0].llvm_project_revision
@@ -313,15 +310,17 @@ def v4_machine(id):
                                          run.start_time.isoformat(),
                                          run.end_time.isoformat()))
         return flask.jsonify(**json_obj)
-    try:
-        return render_template("v4_machine.html",
-                               testsuite_name=g.testsuite_name,
-                               id=id,
-                               associated_runs=associated_runs,
-                               machines=machines,
-                               **ts_data(ts))
-    except NoResultFound:
-        abort(404)
+
+    machines = ts.query(ts.Machine).all()
+    relatives = [m for m in machines if m.name == machine.name]
+    return render_template("v4_machine.html",
+                           testsuite_name=g.testsuite_name,
+                           id=id,
+                           associated_runs=associated_runs,
+                           machine=machine,
+                           machines=machines,
+                           relatives=relatives,
+                           **ts_data(ts))
 
 
 class V4RequestInfo(object):




More information about the llvm-commits mailing list