Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fake request for profile cmd so quickcache works properly #35521

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions corehq/apps/ota/management/commands/profile_restore.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cProfile
from unittest.mock import patch

from django.core.management import BaseCommand

Expand All @@ -19,6 +20,10 @@
"""


class FakeRequest:
...


class Command(BaseCommand):
"""Runs a profiled restore for the provided user"""

Expand All @@ -34,11 +39,12 @@ def handle(self, username, domain, **options):

filename = f'restore-{get_timestamp_for_filename()}.prof'
profile = cProfile.Profile()
profile.enable()
response, timing_context = get_restore_response(
domain, couch_user, app_id=app_id, version="2.0"
)
profile.disable()
with patch('corehq.util.quickcache.get_request', lambda: FakeRequest()):
profile.enable()
response, timing_context = get_restore_response(
domain, couch_user, app_id=app_id, version="2.0"
)
profile.disable()
profile.dump_stats(filename)

timing_context.print()
Expand Down
Loading