{"action":"created","comment":{"url":"https://api.github.com/repos/getsentry/sentry/pulls/comments/148923010","pull_request_review_id":74247079,"id":148923010,"diff_hunk":"@@ -608,18 +608,42 @@ def save(self, project, raw=False):\n         # store a reference to the group id to guarantee validation of isolation\n         event.data.bind_ref(event)\n \n-        try:\n-            with transaction.atomic(using=router.db_for_write(EventMapping)):\n-                EventMapping.objects.create(project=project, group=group, event_id=event_id)\n-        except IntegrityError:\n+        # When an event was sampled, the canonical source of truth\n+        # is the EventMapping table since we aren't going to be writing out an actual\n+        # Event row. Otherwise, if the Event isn't being sampled, we can safely\n+        # rely on the Event table itself as the source of truth and ignore\n+        # EventMapping since it's redundant information.\n+        if is_sample:\n+            try:\n+                with transaction.atomic(using=router.db_for_write(EventMapping)):\n+                    EventMapping.objects.create(project=project, group=group, event_id=event_id)\n+            except IntegrityError:\n+                self.logger.info(\n+                    'duplicate.found',\n+                    exc_info=True,\n+                    extra={\n+                        'event_uuid': event_id,\n+                        'project_id': project.id,\n+                        'group_id': group.id,\n+                        'model': EventMapping.__name__,\n+                    }\n+                )\n+                return event\n+\n+        # We now always need to check the Event table for dupes\n+        # since EventMapping isn't exactly the canonical source of truth.\n+        if Event.objects.filter(\n+            project_id=project.id,\n+            event_id=event_id,\n+        ).exists():\n             self.logger.info(\n                 'duplicate.found',\n                 exc_info=True,\n                 extra={\n                     'event_uuid': event_id,\n                     'project_id': project.id,\n                     'group_id': group.id,\n-                    'model': EventMapping.__name__,\n+                    'model': Event.__name__,\n                 }\n             )\n             return event","path":"src/sentry/event_manager.py","position":47,"original_position":47,"commit_id":"ff9ecce07c263be9f04dd6dc8628aaa7b046fde8","original_commit_id":"ff9ecce07c263be9f04dd6dc8628aaa7b046fde8","user":{"login":"tkaemming","id":65315,"avatar_url":"https://avatars0.githubusercontent.com/u/65315?v=4","gravatar_id":"","url":"https://api.github.com/users/tkaemming","html_url":"https://github.com/tkaemming","followers_url":"https://api.github.com/users/tkaemming/followers","following_url":"https://api.github.com/users/tkaemming/following{/other_user}","gists_url":"https://api.github.com/users/tkaemming/gists{/gist_id}","starred_url":"https://api.github.com/users/tkaemming/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkaemming/subscriptions","organizations_url":"https://api.github.com/users/tkaemming/orgs","repos_url":"https://api.github.com/users/tkaemming/repos","events_url":"https://api.github.com/users/tkaemming/events{/privacy}","received_events_url":"https://api.github.com/users/tkaemming/received_events","type":"User","site_admin":false},"body":"Hi","created_at":"2017-11-04T04:45:14Z","updated_at":"2017-11-04T04:45:14Z","html_url":"https://github.com/getsentry/sentry/pull/6505#discussion_r148923010","pull_request_url":"https://api.github.com/repos/getsentry/sentry/pulls/6505","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/comments/148923010"},"html":{"href":"https://github.com/getsentry/sentry/pull/6505#discussion_r148923010"},"pull_request":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/6505"}},"in_reply_to_id":148907225},"pull_request":{"url":"https://api.github.com/repos/getsentry/sentry/pulls/6505","id":150420421,"html_url":"https://github.com/getsentry/sentry/pull/6505","diff_url":"https://github.com/getsentry/sentry/pull/6505.diff","patch_url":"https://github.com/getsentry/sentry/pull/6505.patch","issue_url":"https://api.github.com/repos/getsentry/sentry/issues/6505","number":6505,"state":"open","locked":false,"title":"ref: Don't use EventMapping for non-sampled events","user":{"login":"mattrobenolt","id":375744,"avatar_url":"https://avatars1.githubusercontent.com/u/375744?v=4","gravatar_id":"","url":"https://api.github.com/users/mattrobenolt","html_url":"https://github.com/mattrobenolt","followers_url":"https://api.github.com/users/mattrobenolt/followers","following_url":"https://api.github.com/users/mattrobenolt/following{/other_user}","gists_url":"https://api.github.com/users/mattrobenolt/gists{/gist_id}","starred_url":"https://api.github.com/users/mattrobenolt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattrobenolt/subscriptions","organizations_url":"https://api.github.com/users/mattrobenolt/orgs","repos_url":"https://api.github.com/users/mattrobenolt/repos","events_url":"https://api.github.com/users/mattrobenolt/events{/privacy}","received_events_url":"https://api.github.com/users/mattrobenolt/received_events","type":"User","site_admin":false},"body":"Historically, EventMapping was used for pairing the string UUID \"event_id\" to the Group which it came from. This was primarily useful and important when Events were being sampled, and there was little guarantee that a specific Event row would actually exist, so EventMapping was used as the canonical source of all event_id -> group mappings.\r\n\r\nNow, with the advent of being able to disable sampling, it doesn't make sense to store redundant data in EventMapping. We could just leverage the canonical Event table.\r\n\r\nThis helps with 2 things:\r\n\r\n* Most of sentry.io data is not sampled anymore, so we'd save a considerable amount of data in the eventmapping table.\r\n* EventMapping is pruned to 7 day history, which means looking up an event that is more than 7 days ago fails, since the mapping has been deleted. If we always look at Event, there's access for full history instead of maintaining this secondary lookup.","created_at":"2017-11-02T22:33:38Z","updated_at":"2017-11-04T04:45:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"67851df453b8b1e76e472478d6dee02cd459d24f","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/getsentry/sentry/pulls/6505/commits","review_comments_url":"https://api.github.com/repos/getsentry/sentry/pulls/6505/comments","review_comment_url":"https://api.github.com/repos/getsentry/sentry/pulls/comments{/number}","comments_url":"https://api.github.com/repos/getsentry/sentry/issues/6505/comments","statuses_url":"https://api.github.com/repos/getsentry/sentry/statuses/ff9ecce07c263be9f04dd6dc8628aaa7b046fde8","head":{"label":"getsentry:cheaper-event-mapping","ref":"cheaper-event-mapping","sha":"ff9ecce07c263be9f04dd6dc8628aaa7b046fde8","user":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars0.githubusercontent.com/u/1396951?v=4","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"repo":{"id":873328,"name":"sentry","full_name":"getsentry/sentry","owner":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars0.githubusercontent.com/u/1396951?v=4","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getsentry/sentry","description":"Sentry is a cross-platform crash reporting and aggregation platform.","fork":false,"url":"https://api.github.com/repos/getsentry/sentry","forks_url":"https://api.github.com/repos/getsentry/sentry/forks","keys_url":"https://api.github.com/repos/getsentry/sentry/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getsentry/sentry/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getsentry/sentry/teams","hooks_url":"https://api.github.com/repos/getsentry/sentry/hooks","issue_events_url":"https://api.github.com/repos/getsentry/sentry/issues/events{/number}","events_url":"https://api.github.com/repos/getsentry/sentry/events","assignees_url":"https://api.github.com/repos/getsentry/sentry/assignees{/user}","branches_url":"https://api.github.com/repos/getsentry/sentry/branches{/branch}","tags_url":"https://api.github.com/repos/getsentry/sentry/tags","blobs_url":"https://api.github.com/repos/getsentry/sentry/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getsentry/sentry/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getsentry/sentry/git/refs{/sha}","trees_url":"https://api.github.com/repos/getsentry/sentry/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getsentry/sentry/statuses/{sha}","languages_url":"https://api.github.com/repos/getsentry/sentry/languages","stargazers_url":"https://api.github.com/repos/getsentry/sentry/stargazers","contributors_url":"https://api.github.com/repos/getsentry/sentry/contributors","subscribers_url":"https://api.github.com/repos/getsentry/sentry/subscribers","subscription_url":"https://api.github.com/repos/getsentry/sentry/subscription","commits_url":"https://api.github.com/repos/getsentry/sentry/commits{/sha}","git_commits_url":"https://api.github.com/repos/getsentry/sentry/git/commits{/sha}","comments_url":"https://api.github.com/repos/getsentry/sentry/comments{/number}","issue_comment_url":"https://api.github.com/repos/getsentry/sentry/issues/comments{/number}","contents_url":"https://api.github.com/repos/getsentry/sentry/contents/{+path}","compare_url":"https://api.github.com/repos/getsentry/sentry/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getsentry/sentry/merges","archive_url":"https://api.github.com/repos/getsentry/sentry/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getsentry/sentry/downloads","issues_url":"https://api.github.com/repos/getsentry/sentry/issues{/number}","pulls_url":"https://api.github.com/repos/getsentry/sentry/pulls{/number}","milestones_url":"https://api.github.com/repos/getsentry/sentry/milestones{/number}","notifications_url":"https://api.github.com/repos/getsentry/sentry/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getsentry/sentry/labels{/name}","releases_url":"https://api.github.com/repos/getsentry/sentry/releases{/id}","deployments_url":"https://api.github.com/repos/getsentry/sentry/deployments","created_at":"2010-08-30T22:06:41Z","updated_at":"2017-11-04T02:45:23Z","pushed_at":"2017-11-03T22:27:48Z","git_url":"git://github.com/getsentry/sentry.git","ssh_url":"git@github.com:getsentry/sentry.git","clone_url":"https://github.com/getsentry/sentry.git","svn_url":"https://github.com/getsentry/sentry","homepage":"https://sentry.io","size":73941,"stargazers_count":14413,"watchers_count":14413,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1745,"mirror_url":null,"archived":false,"open_issues_count":681,"forks":1745,"open_issues":681,"watchers":14413,"default_branch":"master"}},"base":{"label":"getsentry:master","ref":"master","sha":"7c13bbcdb29a11b00c057cb10bccc2aae773658a","user":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars0.githubusercontent.com/u/1396951?v=4","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"repo":{"id":873328,"name":"sentry","full_name":"getsentry/sentry","owner":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars0.githubusercontent.com/u/1396951?v=4","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getsentry/sentry","description":"Sentry is a cross-platform crash reporting and aggregation platform.","fork":false,"url":"https://api.github.com/repos/getsentry/sentry","forks_url":"https://api.github.com/repos/getsentry/sentry/forks","keys_url":"https://api.github.com/repos/getsentry/sentry/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getsentry/sentry/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getsentry/sentry/teams","hooks_url":"https://api.github.com/repos/getsentry/sentry/hooks","issue_events_url":"https://api.github.com/repos/getsentry/sentry/issues/events{/number}","events_url":"https://api.github.com/repos/getsentry/sentry/events","assignees_url":"https://api.github.com/repos/getsentry/sentry/assignees{/user}","branches_url":"https://api.github.com/repos/getsentry/sentry/branches{/branch}","tags_url":"https://api.github.com/repos/getsentry/sentry/tags","blobs_url":"https://api.github.com/repos/getsentry/sentry/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getsentry/sentry/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getsentry/sentry/git/refs{/sha}","trees_url":"https://api.github.com/repos/getsentry/sentry/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getsentry/sentry/statuses/{sha}","languages_url":"https://api.github.com/repos/getsentry/sentry/languages","stargazers_url":"https://api.github.com/repos/getsentry/sentry/stargazers","contributors_url":"https://api.github.com/repos/getsentry/sentry/contributors","subscribers_url":"https://api.github.com/repos/getsentry/sentry/subscribers","subscription_url":"https://api.github.com/repos/getsentry/sentry/subscription","commits_url":"https://api.github.com/repos/getsentry/sentry/commits{/sha}","git_commits_url":"https://api.github.com/repos/getsentry/sentry/git/commits{/sha}","comments_url":"https://api.github.com/repos/getsentry/sentry/comments{/number}","issue_comment_url":"https://api.github.com/repos/getsentry/sentry/issues/comments{/number}","contents_url":"https://api.github.com/repos/getsentry/sentry/contents/{+path}","compare_url":"https://api.github.com/repos/getsentry/sentry/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getsentry/sentry/merges","archive_url":"https://api.github.com/repos/getsentry/sentry/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getsentry/sentry/downloads","issues_url":"https://api.github.com/repos/getsentry/sentry/issues{/number}","pulls_url":"https://api.github.com/repos/getsentry/sentry/pulls{/number}","milestones_url":"https://api.github.com/repos/getsentry/sentry/milestones{/number}","notifications_url":"https://api.github.com/repos/getsentry/sentry/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getsentry/sentry/labels{/name}","releases_url":"https://api.github.com/repos/getsentry/sentry/releases{/id}","deployments_url":"https://api.github.com/repos/getsentry/sentry/deployments","created_at":"2010-08-30T22:06:41Z","updated_at":"2017-11-04T02:45:23Z","pushed_at":"2017-11-03T22:27:48Z","git_url":"git://github.com/getsentry/sentry.git","ssh_url":"git@github.com:getsentry/sentry.git","clone_url":"https://github.com/getsentry/sentry.git","svn_url":"https://github.com/getsentry/sentry","homepage":"https://sentry.io","size":73941,"stargazers_count":14413,"watchers_count":14413,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1745,"mirror_url":null,"archived":false,"open_issues_count":681,"forks":1745,"open_issues":681,"watchers":14413,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/6505"},"html":{"href":"https://github.com/getsentry/sentry/pull/6505"},"issue":{"href":"https://api.github.com/repos/getsentry/sentry/issues/6505"},"comments":{"href":"https://api.github.com/repos/getsentry/sentry/issues/6505/comments"},"review_comments":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/6505/comments"},"review_comment":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/6505/commits"},"statuses":{"href":"https://api.github.com/repos/getsentry/sentry/statuses/ff9ecce07c263be9f04dd6dc8628aaa7b046fde8"}},"author_association":"OWNER"}}
{"actor":{"display_login":"tkaemming"}}