Updates were registering lot of duplicate tests, causing perf issues

This commit is contained in:
Alexandre Aubin 2019-01-22 16:07:00 +00:00
parent 2f179a32d1
commit 5f1cc27954

View file

@ -39,14 +39,15 @@ class AppCIBranch(db.Model):
def most_recent_tests_per_app(self): def most_recent_tests_per_app(self):
apps = App.query.filter_by(ci_enabled=True).all() apps = App.query.filter_by(ci_enabled=True).all()
most_recent_tests = AppCIResult.query \
.filter_by(branch = self) \
.order_by('date desc') \
.all()
for app in apps: for app in apps:
most_recent_test = AppCIResult.query \ most_recent_test = [ t for t in most_recent_tests if t.app == app ]
.filter_by(branch = self) \
.filter_by(app = app) \
.order_by('date desc') \
.first()
if most_recent_test: if most_recent_test:
yield most_recent_test yield most_recent_test[0]
else: else:
yield AppCIResult(app = app, yield AppCIResult(app = app,
branch = self, branch = self,
@ -122,11 +123,20 @@ class AppCI():
for test, result in zip(AppCI.tests, test_summary["detailled_success"]): for test, result in zip(AppCI.tests, test_summary["detailled_success"]):
test_results[test] = bool(int(result)) if result in [ "1", "0" ] else None test_results[test] = bool(int(result)) if result in [ "1", "0" ] else None
results = AppCIResult(app = App.query.filter_by(name=test_summary["app"]).first(), app = App.query.filter_by(name=test_summary["app"]).first()
branch = cibranch, date = datetime.datetime.fromtimestamp(test_summary["timestamp"])
level = test_summary["level"],
date = datetime.datetime.fromtimestamp(test_summary["timestamp"]), existing_test = AppCIResult.query \
results = test_results) .filter_by(branch = cibranch) \
db.session.add(results) .filter_by(date = date) \
.first()
if not existing_test:
results = AppCIResult(app = app,
branch = cibranch,
level = test_summary["level"],
date = date,
results = test_results)
db.session.add(results)
db.session.commit() db.session.commit()