Browse Source

In channels admin, don't show the notification counts, querying it is too expensive.

pull/415/head
Pēteris Caune 4 years ago
parent
commit
c75a37570e
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 11 additions and 15 deletions
  1. +1
    -1
      hc/accounts/admin.py
  2. +10
    -14
      hc/api/admin.py

+ 1
- 1
hc/accounts/admin.py View File

@ -147,7 +147,7 @@ class ProfileAdmin(admin.ModelAdmin):
@mark_safe @mark_safe
def checks(self, obj): def checks(self, obj):
s = "%d of %d" % (obj.num_checks, obj.check_limit) s = "%d of %d" % (obj.num_checks, obj.check_limit)
if obj.num_checks > 10:
if obj.num_checks > 1:
s = "<b>%s</b>" % s s = "<b>%s</b>" % s
return s return s


+ 10
- 14
hc/api/admin.py View File

@ -175,14 +175,7 @@ class ChannelsAdmin(admin.ModelAdmin):
css = {"all": ("css/admin/channels.css",)} css = {"all": ("css/admin/channels.css",)}
search_fields = ["value", "project__owner__email"] search_fields = ["value", "project__owner__email"]
list_display = (
"id",
"kind_",
"name",
"project_",
"value",
"num_notifications",
)
list_display = ("id", "transport", "name", "project_", "value", "ok")
list_filter = ("kind",) list_filter = ("kind",)
raw_id_fields = ("project", "checks") raw_id_fields = ("project", "checks")
@ -195,20 +188,23 @@ class ChannelsAdmin(admin.ModelAdmin):
def get_queryset(self, request): def get_queryset(self, request):
qs = super().get_queryset(request) qs = super().get_queryset(request)
qs = qs.annotate(Count("notification", distinct=True))
qs = qs.annotate(project_code=F("project__code")) qs = qs.annotate(project_code=F("project__code"))
qs = qs.annotate(project_name=F("project__name")) qs = qs.annotate(project_name=F("project__name"))
qs = qs.annotate(email=F("project__owner__email")) qs = qs.annotate(email=F("project__owner__email"))
return qs return qs
@mark_safe @mark_safe
def kind_(self, obj):
return f'<span class="icon-{ obj.kind }"></span> &nbsp; {obj.kind}'
def transport(self, obj):
note = ""
if obj.kind == "email" and not obj.email_verified:
note = " (not verified)"
return f'<span class="icon-{ obj.kind }"></span> &nbsp; {obj.kind}{note}'
def num_notifications(self, obj):
return obj.notification__count
def ok(self, obj):
return False if obj.last_error else True
num_notifications.short_description = "# Notifications"
ok.boolean = True
@admin.register(Notification) @admin.register(Notification)


Loading…
Cancel
Save