Skip to content

Commit

Permalink
Alternate alternate approach 🙃
Browse files Browse the repository at this point in the history
  • Loading branch information
bmispelon committed Dec 11, 2024
1 parent 14e2b13 commit ce82b7a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
15 changes: 0 additions & 15 deletions dashboard/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit ce82b7a

Please sign in to comment.