Skip to content

Commit

Permalink
Merge pull request #35521 from dimagi/es/mobile-ucr
Browse files Browse the repository at this point in the history
Make fake request for profile cmd so quickcache works properly
  • Loading branch information
esoergel authored Dec 13, 2024
2 parents bcc5b6d + 95dd6aa commit bc7939e
Showing 1 changed file with 11 additions and 5 deletions.
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

0 comments on commit bc7939e

Please sign in to comment.