Skip to content

Commit decd008

Browse files
committed
Remove TimeLimitedPaginator since not DB agnostic
TimeLimitedPaginator was used to make the ArkAdmin model load more quickly in Django Admin for large ARK tables. However, it uses a hack specific to Postgres. I removed it (it didn't make the admin very useful anyway) in favor of making Arklet DB agnostic.
1 parent ce8d9aa commit decd008

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

ark/admin.py

+18-26
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,46 @@
1+
"""Django Admin models for Arklet."""
2+
13
from django.contrib import admin
2-
from django.core.paginator import Paginator
3-
from django.db import OperationalError, connection, transaction
4-
from django.utils.functional import cached_property
54

65
from ark.models import Ark, Key, Naan, Shoulder, User
76

87

9-
class TimeLimitedPaginator(Paginator):
10-
"""
11-
Paginator that enforces a timeout on the count operation.
12-
If the operations times out, a fake bogus value is
13-
returned instead.
14-
15-
Lifted from: https://web.archive.org/web/20210422225156/https://hakibenita.com/optimizing-the-django-admin-paginator
16-
"""
17-
18-
@cached_property
19-
def count(self):
20-
# We set the timeout in a db transaction to prevent it from
21-
# affecting other transactions.
22-
with transaction.atomic(), connection.cursor() as cursor:
23-
cursor.execute("SET LOCAL statement_timeout TO 1000;")
24-
try:
25-
return super().count
26-
except OperationalError:
27-
return 9999999999
28-
29-
308
@admin.register(User)
319
class UserAdmin(admin.ModelAdmin):
32-
pass
10+
"""Django Admin model for ARK admin users."""
3311

3412

3513
@admin.register(Naan)
3614
class NaanAdmin(admin.ModelAdmin):
15+
"""Django Admin model for Name Assignment Authority Number bearing organizations."""
16+
3717
list_display = ["name", "naan"]
3818

3919

4020
@admin.register(Shoulder)
4121
class ShoulderAdmin(admin.ModelAdmin):
22+
"""Django Admin model for ARK shoulders."""
23+
4224
list_display = ["shoulder", "name", "naan"]
4325

4426

4527
@admin.register(Ark)
4628
class ArkAdmin(admin.ModelAdmin):
29+
"""Django Admin model for ARKs.
30+
31+
In practice, stock Django Admin doesn't work well for large randomly sorted tables.
32+
This view will tend to take a long time to load as a full table count query is run.
33+
"""
34+
4735
list_display = ["ark", "url"]
4836
show_full_result_count = False
49-
paginator = TimeLimitedPaginator
5037

5138

5239
@admin.register(Key)
5340
class KeyAdmin(admin.ModelAdmin):
41+
"""Django Admin model for managing Arklet access keys.
42+
43+
These access keys are used to mint and bind ARKs via the Arklet API.
44+
"""
45+
5446
list_display = ["key", "naan", "active"]

ark/management/commands/mintarks.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class Command(BaseCommand):
1414
"""Mint ark_count ARKs for the given naan and shoulder."""
15+
1516
help = "Mint ARKs in bulk"
1617

1718
def add_arguments(self, parser):

setup.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[flake8]
2-
# Match black line length
3-
max-line-length = 88
2+
# Black won't auto-format away long strings but flake8 will still complain
3+
max-line-length = 138
44
# W503: Line break occurred before a binary operator
55
# E203: See https://github.com/PyCQA/pycodestyle/issues/373
66
ignore = E203, W503

0 commit comments

Comments
 (0)