mirror of
https://github.com/barkeser2002/offline-db.git
synced 2026-09-25 04:39:59 +03:00
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Senpai-YoloBot <41898282+github-actions[bot]@users.noreply.github.com>
30 lines
907 B
Python
30 lines
907 B
Python
import os
|
|
import django
|
|
from django.test.utils import CaptureQueriesContext
|
|
from django.db import connection
|
|
from django.core.cache import cache
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'aniscrap_core.settings')
|
|
django.setup()
|
|
|
|
from users.models import User, Badge, UserBadge
|
|
from content.models import Anime, Subscription, Review
|
|
from users.services import check_badges
|
|
|
|
# Clear cache to force it to do the actual check
|
|
cache.clear()
|
|
|
|
try:
|
|
user = User.objects.get(username='perftest_manual')
|
|
except User.DoesNotExist:
|
|
user = User.objects.create_user(username='perftest_manual', password='password')
|
|
|
|
# We want to measure the queries when badges are not cached for the specific user
|
|
|
|
with CaptureQueriesContext(connection) as ctx:
|
|
check_badges(user)
|
|
|
|
print(f"\nQueries executed (cold cache, check_badges): {len(ctx.captured_queries)}")
|
|
for q in ctx.captured_queries:
|
|
print(q['sql'])
|