From ce82b7a510e51c3b9ff3798bb25bab032aee74ca Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Wed, 11 Dec 2024 14:38:33 +0100 Subject: [PATCH] =?UTF-8?q?Alternate=20alternate=20approach=20=F0=9F=99=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/models.py | 15 --------------- dashboard/views.py | 3 +-- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/dashboard/models.py b/dashboard/models.py index b8832073a..1aa11ffa9 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -1,8 +1,6 @@ import ast import calendar import datetime -import operator -from functools import reduce import requests from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation @@ -254,17 +252,6 @@ def link(self): return self.urljoin(self.jenkins_root_url, "job", self.build_name) -class DatumQuerySet(models.QuerySet): - def metrics(self, *metrics): - """ - Return only the data from the given metrics. - """ - if not metrics: - return self.none() - qobjs = [models.Q(content_type=m.content_type, object_id=m.pk) for m in metrics] - return self.filter(reduce(operator.or_, qobjs)) - - class Datum(models.Model): metric = GenericForeignKey() content_type = models.ForeignKey( @@ -274,8 +261,6 @@ class Datum(models.Model): timestamp = models.DateTimeField(default=datetime.datetime.now) measurement = models.BigIntegerField() - objects = DatumQuerySet.as_manager() - class Meta: ordering = ["-timestamp"] get_latest_by = "timestamp" diff --git a/dashboard/views.py b/dashboard/views.py index a2a449119..ab859f882 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -25,8 +25,7 @@ def index(request): metrics = sorted(metrics, key=operator.attrgetter("display_position")) metric_latest_querysets = [ - Datum.objects.metrics(metric).order_by("-timestamp")[0:1] - for metric in metrics + metric.data.order_by("-timestamp")[0:1] for metric in metrics ] data_latest = Datum.objects.none().union(*metric_latest_querysets) latest_by_metric = {