{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/26961834","id":26961834,"diff_hunk":"@@ -0,0 +1,161 @@\n+from casexml.apps.case.mock import CaseBlock\n+from casexml.apps.phone.caselogic import filter_cases_modified_elsewhere_since_sync, get_related_cases\n+from casexml.apps.phone.tests.test_sync_mode import SyncBaseTest, PARENT_TYPE\n+from casexml.apps.phone.tests.utils import synclog_from_restore_payload\n+from casexml.apps.case.tests.util import assert_user_has_cases\n+from casexml.apps.phone.models import User\n+from casexml.apps.phone.restore import generate_restore_payload, RestoreConfig, get_case_payload, \\\n+    get_case_payload_batched\n+from dimagi.utils.decorators.profile import line_profile\n+from casexml.apps.case.xml import V2\n+from datetime import datetime\n+\n+USER_ID = \"main_user\"\n+USERNAME = \"syncguy\"\n+OTHER_USER_ID = \"someone_else\"\n+OTHER_USERNAME = \"ferrel\"\n+SHARED_ID = \"our_group\"\n+\n+REFERRAL_USERNAME = 'referral_user'\n+REFERRAL_USER_ID = 'referral_user_id'\n+REFERRED_TO_GROUP = 'other_group'\n+REFERRAL_TYPE = 'referral'\n+\n+\n+class SyncPerformanceTest(SyncBaseTest):\n+    \"\"\"\n+    Tests the interaction of two users in sync mode doing various things\n+    \"\"\"\n+\n+    def setUp(self):\n+        super(SyncPerformanceTest, self).setUp()\n+        # the other user is an \"owner\" of the original users cases as well,\n+        # for convenience\n+        self.other_user = User(user_id=OTHER_USER_ID, username=OTHER_USERNAME,\n+                               password=\"changeme\", date_joined=datetime(2011, 6, 9),\n+                               additional_owner_ids=[SHARED_ID])\n+\n+        self.referral_user = User(user_id=REFERRAL_USER_ID, username=REFERRAL_USERNAME,\n+                               password=\"changeme\", date_joined=datetime(2011, 6, 9),\n+                               additional_owner_ids=[REFERRED_TO_GROUP])\n+\n+        # this creates the initial blank sync token in the database\n+        self.other_sync_log = synclog_from_restore_payload(generate_restore_payload(self.other_user))\n+        self.referral_sync_log = synclog_from_restore_payload(generate_restore_payload(self.referral_user))\n+\n+        self.assertTrue(SHARED_ID in self.other_sync_log.owner_ids_on_phone)\n+        self.assertTrue(OTHER_USER_ID in self.other_sync_log.owner_ids_on_phone)\n+\n+        self.user.additional_owner_ids = [SHARED_ID]\n+        self.sync_log = synclog_from_restore_payload(generate_restore_payload(self.user))\n+        self.assertTrue(SHARED_ID in self.sync_log.owner_ids_on_phone)\n+        self.assertTrue(USER_ID in self.sync_log.owner_ids_on_phone)\n+\n+    @line_profile([\n+        RestoreConfig.get_payload,\n+        get_case_payload,\n+        get_case_payload_batched,\n+        get_related_cases,\n+        filter_cases_modified_elsewhere_since_sync\n+    ])\n+    def test_profile_filter_cases_modified_elsewhere_since_sync(self):\n+        total_cases = 100\n+        proportion_modified = 0\n+\n+        modified = total_cases * proportion_modified\n+        id_list = ['case_id_{}'.format(i) for i in range(total_cases)]\n+        self._createCaseStubs(id_list, user_id=USER_ID, owner_id=SHARED_ID)\n+\n+        caseblocks = []\n+        for case_id in id_list[:modified]:\n+            caseblocks.append(CaseBlock(\n+                case_id=case_id,\n+                user_id=OTHER_USER_ID,\n+                version=V2,\n+                update={'favorite_color': 'blue'}\n+            ).as_xml())\n+        self._postFakeWithSyncToken(caseblocks, self.other_sync_log.get_id)\n+\n+        assert_user_has_cases(self, self.user, id_list[:modified], restore_id=self.sync_log.get_id)\n+\n+    @line_profile([\n+        RestoreConfig.get_payload,\n+        get_case_payload,\n+        get_case_payload_batched,\n+        get_related_cases,\n+        filter_cases_modified_elsewhere_since_sync\n+    ])\n+    def test_profile_get_related_cases(self):\n+        total_parent_cases = 50\n+\n+        id_list = ['case_id_{}'.format(i) for i in range(total_parent_cases)]\n+        self._createCaseStubs(id_list, user_id=USER_ID, owner_id=SHARED_ID)\n+\n+        new_case_ids = []\n+        caseblocks = []\n+        for i, parent_case_id in enumerate(id_list):\n+            case_id = 'case_id_referral_{}'.format(i)\n+            new_case_ids.append(case_id)\n+            caseblocks.append(CaseBlock(\n+                create=True,\n+                case_id=case_id,\n+                user_id=USER_ID,\n+                owner_id=REFERRED_TO_GROUP,\n+                case_type=REFERRAL_TYPE,\n+                version=V2,\n+                index={'parent': (PARENT_TYPE, parent_case_id)}\n+            ).as_xml())\n+        self._postFakeWithSyncToken(caseblocks, self.sync_log.get_id)","path":"corehq/ex-submodules/casexml/apps/phone/tests/performance_tests.py","position":108,"original_position":108,"commit_id":"ea62e17b2d855191cc7b69ed4623caca8f4a7667","original_commit_id":"ea62e17b2d855191cc7b69ed4623caca8f4a7667","user":{"login":"czue","id":66555,"avatar_url":"https://avatars.githubusercontent.com/u/66555?v=3","gravatar_id":"","url":"https://api.github.com/users/czue","html_url":"https://github.com/czue","followers_url":"https://api.github.com/users/czue/followers","following_url":"https://api.github.com/users/czue/following{/other_user}","gists_url":"https://api.github.com/users/czue/gists{/gist_id}","starred_url":"https://api.github.com/users/czue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/czue/subscriptions","organizations_url":"https://api.github.com/users/czue/orgs","repos_url":"https://api.github.com/users/czue/repos","events_url":"https://api.github.com/users/czue/events{/privacy}","received_events_url":"https://api.github.com/users/czue/received_events","type":"User","site_admin":false},"body":"Nothing jumps out but happy to take a look. I have to imagine we support creating a parent and children in the same form.... right? Would be crazy if that's never come up till now.","created_at":"2015-03-23T17:59:03Z","updated_at":"2015-03-23T17:59:03Z","html_url":"https://github.com/dimagi/commcare-hq/pull/5945#discussion_r26961834","pull_request_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/5945","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/26961834"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/5945#discussion_r26961834"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/5945"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/5945","id":31528953,"html_url":"https://github.com/dimagi/commcare-hq/pull/5945","diff_url":"https://github.com/dimagi/commcare-hq/pull/5945.diff","patch_url":"https://github.com/dimagi/commcare-hq/pull/5945.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/5945","number":5945,"state":"open","locked":false,"title":"performance tests","user":{"login":"snopoke","id":249606,"avatar_url":"https://avatars.githubusercontent.com/u/249606?v=3","gravatar_id":"","url":"https://api.github.com/users/snopoke","html_url":"https://github.com/snopoke","followers_url":"https://api.github.com/users/snopoke/followers","following_url":"https://api.github.com/users/snopoke/following{/other_user}","gists_url":"https://api.github.com/users/snopoke/gists{/gist_id}","starred_url":"https://api.github.com/users/snopoke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snopoke/subscriptions","organizations_url":"https://api.github.com/users/snopoke/orgs","repos_url":"https://api.github.com/users/snopoke/repos","events_url":"https://api.github.com/users/snopoke/events{/privacy}","received_events_url":"https://api.github.com/users/snopoke/received_events","type":"User","site_admin":false},"body":"@dannyroberts @czue FYI\r\n\r\nhttps://docs.google.com/a/dimagi.com/spreadsheets/d/17ROce9wpmFs5TuNIoBnXMpTreWUynd4QRGAFCX4LEso/edit#gid=0","created_at":"2015-03-19T14:38:21Z","updated_at":"2015-03-23T17:59:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"46118ae2d8e53580b39c9d46d1ed1833bed0c5b7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/5945/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/5945/comments","review_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/5945/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/ea62e17b2d855191cc7b69ed4623caca8f4a7667","head":{"label":"dimagi:restore_profiles","ref":"restore_profiles","sha":"ea62e17b2d855191cc7b69ed4623caca8f4a7667","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":247278,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","created_at":"2009-07-09T17:00:07Z","updated_at":"2015-03-23T17:49:14Z","pushed_at":"2015-03-23T16:29:40Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"http://www.commcarehq.org","size":332455,"stargazers_count":43,"watchers_count":43,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":57,"mirror_url":null,"open_issues_count":45,"forks":57,"open_issues":45,"watchers":43,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"8b396b1d9266db771bc4188138b21ed47cfc2976","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":247278,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","created_at":"2009-07-09T17:00:07Z","updated_at":"2015-03-23T17:49:14Z","pushed_at":"2015-03-23T16:29:40Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"http://www.commcarehq.org","size":332455,"stargazers_count":43,"watchers_count":43,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":57,"mirror_url":null,"open_issues_count":45,"forks":57,"open_issues":45,"watchers":43,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/5945"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/5945"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/5945"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/5945/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/5945/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/5945/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-hq/statuses/ea62e17b2d855191cc7b69ed4623caca8f4a7667"}}}}