[patchew-devel] [PATCH 3/7] testing: Optimized "testing-get" API call

  • From: Fam Zheng <famz@xxxxxxxxxx>
  • To: patchew-devel@xxxxxxxxxxxxx
  • Date: Wed, 7 Mar 2018 16:46:05 +0800

With "testing.ready" property, we immediately mark series as "ready to
test" when git apply is done, eliminating the need to do a relatively
heavy search query.

Signed-off-by: Fam Zheng <famz@xxxxxxxxxx>
---
 mods/testing.py       | 22 +++++++++++++++++-----
 tests/test_testing.py |  1 +
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/mods/testing.py b/mods/testing.py
index 47933e2..80a22a5 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -23,7 +23,7 @@ import math
 from api.views import APILoginRequiredView
 from api.models import Message, Project, MessageProperty
 from api.search import SearchEngine
-from event import emit_event, declare_event
+from event import emit_event, declare_event, register_handler
 from patchew.logviewer import LogView
 from schema import *
 
@@ -112,6 +112,16 @@ class TestingModule(PatchewModule):
                       test="test name",
                       log="test log",
                       is_timeout="whether the test has timeout")
+        register_handler("SetProperty", self.on_set_property)
+
+    def on_set_property(self, evt, obj, name, value, old_value):
+        if ((isinstance(obj, Message) and obj.is_series_head) \
+            or isinstance(obj, Project)) \
+            and name in ("git.tag", "git.repo") \
+            and old_value is None \
+            and obj.get_property("git.tag") and obj.get_property("git.repo"):
+                self.remove_testing_properties(obj)
+                obj.set_property("testing.ready", 1)
 
     def remove_testing_properties(self, obj, test=""):
         for k in list(obj.get_properties().keys()):
@@ -174,6 +184,7 @@ class TestingModule(PatchewModule):
         all_tests = set([k for k, v in self.get_tests(obj).items() if 
v["enabled"]])
         if all_tests.issubset(done_tests):
             obj.set_property("testing.done", True)
+            obj.set_property("testing.ready", None)
         if all_tests.issubset(done_tests):
             obj.set_property("testing.tested-head", head)
         emit_event("TestingReport", tester=tester, user=user.username,
@@ -430,11 +441,12 @@ class TestingGetView(APILoginRequiredView):
         return po, td
 
     def _find_series_test(self, request, po, tester, capabilities):
-        se = SearchEngine()
-        q = se.search_series("is:applied", "not:old", "not:tested",
-                             "project:" + po.name)
+        q = MessageProperty.objects.filter(name="testing.ready",
+                                           value=1,
+                                           message__project=po)
         candidate = None
-        for s in q:
+        for prop in q:
+            s = prop.message
             test = self._find_applicable_test(request.user, po,
                                               tester, capabilities, s)
             if not test:
diff --git a/tests/test_testing.py b/tests/test_testing.py
index cca3513..300201b 100755
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -46,6 +46,7 @@ class TestingTest(PatchewTestCase):
         if log is not None:
             self.msg.set_property("testing.log.tests", log)
         self.msg.set_property("testing.done", True)
+        self.msg.set_property("testing.ready", None)
 
     def test_basic(self):
         self.api_login()
-- 
2.14.3


Other related posts: