mirror of
https://github.com/barkeser2002/offline-db.git
synced 2026-09-25 04:19:53 +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>
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
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, Episode, Season
|
|
from users.services import check_badges
|
|
|
|
# Clear cache
|
|
cache.clear()
|
|
|
|
try:
|
|
user = User.objects.get(username='perftest_manual3')
|
|
except User.DoesNotExist:
|
|
user = User.objects.create_user(username='perftest_manual3', password='password')
|
|
|
|
anime = Anime.objects.create(title='Test Anime 4')
|
|
season = Season.objects.create(anime=anime, title="Season 1", number=1)
|
|
ep1 = Episode.objects.create(season=season, title="Ep 1", number=1)
|
|
ep2 = Episode.objects.create(season=season, title="Ep 2", number=2)
|
|
|
|
from users.models import WatchLog
|
|
WatchLog.objects.create(user=user, episode=ep1, duration=1200)
|
|
|
|
with CaptureQueriesContext(connection) as ctx:
|
|
check_badges(user)
|
|
|
|
print(f"\nQueries executed (cold cache, with episodes watched): {len(ctx.captured_queries)}")
|
|
for q in ctx.captured_queries:
|
|
print(q['sql'])
|