Skip to content

Commit

Permalink
Make fake request so quickcache works properly
Browse files Browse the repository at this point in the history
If no request or task is active, quickcache doesn't use the locmem
cache.  This makes the profile not an accurate representation of a real
restore
  • Loading branch information
esoergel committed Dec 12, 2024
1 parent f0026b5 commit 95dd6aa
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 95dd6aa

Please sign in to comment.