mirror of
https://github.com/jlengrand/bugsink.git
synced 2026-03-09 23:51:20 +00:00
Add modelcounts command; useful in the context of housekeeping when servers are down
This commit is contained in:
42
bsmain/management/commands/modelcounts.py
Normal file
42
bsmain/management/commands/modelcounts.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django import apps
|
||||
|
||||
from bugsink.transaction import durable_atomic
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
@durable_atomic
|
||||
def handle(self, *args, **options):
|
||||
# Copy/paste from bugsink/views's 'def counts' with removal of the limit_runtime / CachedModelCount parts.
|
||||
|
||||
interesting_apps = [
|
||||
# "admin",
|
||||
# "auth",
|
||||
"bsmain",
|
||||
# "contenttypes",
|
||||
"events",
|
||||
"files",
|
||||
"ingest",
|
||||
"issues",
|
||||
# "phonehome",
|
||||
"projects",
|
||||
"releases",
|
||||
# "sessions",
|
||||
"snappea",
|
||||
"tags",
|
||||
"teams",
|
||||
"users",
|
||||
]
|
||||
|
||||
counts = {}
|
||||
|
||||
for app_label in interesting_apps:
|
||||
counts[app_label] = {}
|
||||
app_config = apps.apps.get_app_config(app_label)
|
||||
for model in app_config.get_models():
|
||||
if model.__name__ == "CachedModelCount":
|
||||
continue # skip the CachedModelCount model itself
|
||||
|
||||
model_name = f"{app_label}.{model.__name__}"
|
||||
print(f"{model_name:<30}{model.objects.count():>12}")
|
||||
@@ -173,6 +173,7 @@ def settings_view(request):
|
||||
@user_passes_test(lambda u: u.is_superuser)
|
||||
@atomic_for_request_method # get a consistent view (barring cached, which are marked as such)
|
||||
def counts(request):
|
||||
# See also: modelcounts management command.
|
||||
interesting_apps = [
|
||||
# "admin",
|
||||
# "auth",
|
||||
|
||||
Reference in New Issue
Block a user