{"action":"created","comment":{"url":"https://api.github.com/repos/goldstar/blackbeard/pulls/comments/48794788","id":48794788,"diff_hunk":"@@ -53,15 +53,26 @@ def unique_identifier\n     end\n \n     def user_id\n+      unless bbd.nil?\n+        VisitorUserTracker.set_visitor_id_for_user(user_id: @user.id, visitor_id: bbd)\n+      end\n+\n+      vid = VisitorUserTracker.get_visitor_id_for_user(@user.id)\n+      return vid if vid\n       @user.id\n     end\n \n     def visitor_id\n-      @visitor_id ||= (controller.request.cookies['bbd'] || generate_visitor_id).to_i\n+      @visitor_id ||= (bbd || generate_visitor_id).to_i\n     end\n \n private\n \n+    def bbd\n+      return nil if controller.nil? || controller.request.nil?\n+      controller.request.cookies['bbd']","path":"lib/blackbeard/context.rb","position":22,"original_position":22,"commit_id":"74addb6dd86567969e9e2f9ac71c440bd468dfb5","original_commit_id":"74addb6dd86567969e9e2f9ac71c440bd468dfb5","user":{"login":"keithcelt","id":499752,"avatar_url":"https://avatars.githubusercontent.com/u/499752?v=3","gravatar_id":"","url":"https://api.github.com/users/keithcelt","html_url":"https://github.com/keithcelt","followers_url":"https://api.github.com/users/keithcelt/followers","following_url":"https://api.github.com/users/keithcelt/following{/other_user}","gists_url":"https://api.github.com/users/keithcelt/gists{/gist_id}","starred_url":"https://api.github.com/users/keithcelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithcelt/subscriptions","organizations_url":"https://api.github.com/users/keithcelt/orgs","repos_url":"https://api.github.com/users/keithcelt/repos","events_url":"https://api.github.com/users/keithcelt/events{/privacy}","received_events_url":"https://api.github.com/users/keithcelt/received_events","type":"User","site_admin":false},"body":"Maybe call `to_i` in this accessor?","created_at":"2016-01-04T23:11:12Z","updated_at":"2016-01-04T23:11:12Z","html_url":"https://github.com/goldstar/blackbeard/pull/9#discussion_r48794788","pull_request_url":"https://api.github.com/repos/goldstar/blackbeard/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/goldstar/blackbeard/pulls/comments/48794788"},"html":{"href":"https://github.com/goldstar/blackbeard/pull/9#discussion_r48794788"},"pull_request":{"href":"https://api.github.com/repos/goldstar/blackbeard/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/goldstar/blackbeard/pulls/9","id":54839674,"html_url":"https://github.com/goldstar/blackbeard/pull/9","diff_url":"https://github.com/goldstar/blackbeard/pull/9.diff","patch_url":"https://github.com/goldstar/blackbeard/pull/9.patch","issue_url":"https://api.github.com/repos/goldstar/blackbeard/issues/9","number":9,"state":"open","locked":false,"title":"Preserve active features if visitors become users","user":{"login":"tlehman","id":261552,"avatar_url":"https://avatars.githubusercontent.com/u/261552?v=3","gravatar_id":"","url":"https://api.github.com/users/tlehman","html_url":"https://github.com/tlehman","followers_url":"https://api.github.com/users/tlehman/followers","following_url":"https://api.github.com/users/tlehman/following{/other_user}","gists_url":"https://api.github.com/users/tlehman/gists{/gist_id}","starred_url":"https://api.github.com/users/tlehman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlehman/subscriptions","organizations_url":"https://api.github.com/users/tlehman/orgs","repos_url":"https://api.github.com/users/tlehman/repos","events_url":"https://api.github.com/users/tlehman/events{/privacy}","received_events_url":"https://api.github.com/users/tlehman/received_events","type":"User","site_admin":false},"body":"In order to preserve which features are active for a visitor when they become a user (either through login or signup), we need to record the value of their visitor id and associate it with their user id.\r\n\r\nThis is an approach to solve this problem, I created a `VistiorUserTracker`, which manages a redis hash from user_ids to visitor_ids. When a person first views the site without being logged in, we create a visitor id and store it as a cookie with key \"bbd\", this PR modifies `Context#user_id` so that if the user has a \"bbd\" cookie value, but there is no stored visitor id for them in redis, we record that.\r\n\r\nThe effect is that visitor_id is sticky, as soon as a user logs in or signs up, we record their visitor_id and then use that forever. Since we are storing the association in redis, we don't have to make any changes to the user model.","created_at":"2015-12-31T00:14:31Z","updated_at":"2016-01-04T23:11:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1d1ab567836659bb71a223162ec2581f550f0bf8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/goldstar/blackbeard/pulls/9/commits","review_comments_url":"https://api.github.com/repos/goldstar/blackbeard/pulls/9/comments","review_comment_url":"https://api.github.com/repos/goldstar/blackbeard/pulls/comments{/number}","comments_url":"https://api.github.com/repos/goldstar/blackbeard/issues/9/comments","statuses_url":"https://api.github.com/repos/goldstar/blackbeard/statuses/74addb6dd86567969e9e2f9ac71c440bd468dfb5","head":{"label":"goldstar:enchantment/91-preserve-feature-visibility-visitor-to-user","ref":"enchantment/91-preserve-feature-visibility-visitor-to-user","sha":"74addb6dd86567969e9e2f9ac71c440bd468dfb5","user":{"login":"goldstar","id":38192,"avatar_url":"https://avatars.githubusercontent.com/u/38192?v=3","gravatar_id":"","url":"https://api.github.com/users/goldstar","html_url":"https://github.com/goldstar","followers_url":"https://api.github.com/users/goldstar/followers","following_url":"https://api.github.com/users/goldstar/following{/other_user}","gists_url":"https://api.github.com/users/goldstar/gists{/gist_id}","starred_url":"https://api.github.com/users/goldstar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goldstar/subscriptions","organizations_url":"https://api.github.com/users/goldstar/orgs","repos_url":"https://api.github.com/users/goldstar/repos","events_url":"https://api.github.com/users/goldstar/events{/privacy}","received_events_url":"https://api.github.com/users/goldstar/received_events","type":"Organization","site_admin":false},"repo":{"id":15953912,"name":"blackbeard","full_name":"goldstar/blackbeard","owner":{"login":"goldstar","id":38192,"avatar_url":"https://avatars.githubusercontent.com/u/38192?v=3","gravatar_id":"","url":"https://api.github.com/users/goldstar","html_url":"https://github.com/goldstar","followers_url":"https://api.github.com/users/goldstar/followers","following_url":"https://api.github.com/users/goldstar/following{/other_user}","gists_url":"https://api.github.com/users/goldstar/gists{/gist_id}","starred_url":"https://api.github.com/users/goldstar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goldstar/subscriptions","organizations_url":"https://api.github.com/users/goldstar/orgs","repos_url":"https://api.github.com/users/goldstar/repos","events_url":"https://api.github.com/users/goldstar/events{/privacy}","received_events_url":"https://api.github.com/users/goldstar/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/goldstar/blackbeard","description":"A Redis backed metrics collector with a Rack dashboard","fork":false,"url":"https://api.github.com/repos/goldstar/blackbeard","forks_url":"https://api.github.com/repos/goldstar/blackbeard/forks","keys_url":"https://api.github.com/repos/goldstar/blackbeard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/goldstar/blackbeard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/goldstar/blackbeard/teams","hooks_url":"https://api.github.com/repos/goldstar/blackbeard/hooks","issue_events_url":"https://api.github.com/repos/goldstar/blackbeard/issues/events{/number}","events_url":"https://api.github.com/repos/goldstar/blackbeard/events","assignees_url":"https://api.github.com/repos/goldstar/blackbeard/assignees{/user}","branches_url":"https://api.github.com/repos/goldstar/blackbeard/branches{/branch}","tags_url":"https://api.github.com/repos/goldstar/blackbeard/tags","blobs_url":"https://api.github.com/repos/goldstar/blackbeard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/goldstar/blackbeard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/goldstar/blackbeard/git/refs{/sha}","trees_url":"https://api.github.com/repos/goldstar/blackbeard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/goldstar/blackbeard/statuses/{sha}","languages_url":"https://api.github.com/repos/goldstar/blackbeard/languages","stargazers_url":"https://api.github.com/repos/goldstar/blackbeard/stargazers","contributors_url":"https://api.github.com/repos/goldstar/blackbeard/contributors","subscribers_url":"https://api.github.com/repos/goldstar/blackbeard/subscribers","subscription_url":"https://api.github.com/repos/goldstar/blackbeard/subscription","commits_url":"https://api.github.com/repos/goldstar/blackbeard/commits{/sha}","git_commits_url":"https://api.github.com/repos/goldstar/blackbeard/git/commits{/sha}","comments_url":"https://api.github.com/repos/goldstar/blackbeard/comments{/number}","issue_comment_url":"https://api.github.com/repos/goldstar/blackbeard/issues/comments{/number}","contents_url":"https://api.github.com/repos/goldstar/blackbeard/contents/{+path}","compare_url":"https://api.github.com/repos/goldstar/blackbeard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/goldstar/blackbeard/merges","archive_url":"https://api.github.com/repos/goldstar/blackbeard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/goldstar/blackbeard/downloads","issues_url":"https://api.github.com/repos/goldstar/blackbeard/issues{/number}","pulls_url":"https://api.github.com/repos/goldstar/blackbeard/pulls{/number}","milestones_url":"https://api.github.com/repos/goldstar/blackbeard/milestones{/number}","notifications_url":"https://api.github.com/repos/goldstar/blackbeard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/goldstar/blackbeard/labels{/name}","releases_url":"https://api.github.com/repos/goldstar/blackbeard/releases{/id}","created_at":"2014-01-16T00:58:05Z","updated_at":"2015-04-28T00:03:10Z","pushed_at":"2015-12-31T00:14:32Z","git_url":"git://github.com/goldstar/blackbeard.git","ssh_url":"git@github.com:goldstar/blackbeard.git","clone_url":"https://github.com/goldstar/blackbeard.git","svn_url":"https://github.com/goldstar/blackbeard","homepage":"","size":371,"stargazers_count":6,"watchers_count":6,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":6,"default_branch":"master"}},"base":{"label":"goldstar:master","ref":"master","sha":"633f23222a13a380e4e00c98a797e3887f3ed01e","user":{"login":"goldstar","id":38192,"avatar_url":"https://avatars.githubusercontent.com/u/38192?v=3","gravatar_id":"","url":"https://api.github.com/users/goldstar","html_url":"https://github.com/goldstar","followers_url":"https://api.github.com/users/goldstar/followers","following_url":"https://api.github.com/users/goldstar/following{/other_user}","gists_url":"https://api.github.com/users/goldstar/gists{/gist_id}","starred_url":"https://api.github.com/users/goldstar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goldstar/subscriptions","organizations_url":"https://api.github.com/users/goldstar/orgs","repos_url":"https://api.github.com/users/goldstar/repos","events_url":"https://api.github.com/users/goldstar/events{/privacy}","received_events_url":"https://api.github.com/users/goldstar/received_events","type":"Organization","site_admin":false},"repo":{"id":15953912,"name":"blackbeard","full_name":"goldstar/blackbeard","owner":{"login":"goldstar","id":38192,"avatar_url":"https://avatars.githubusercontent.com/u/38192?v=3","gravatar_id":"","url":"https://api.github.com/users/goldstar","html_url":"https://github.com/goldstar","followers_url":"https://api.github.com/users/goldstar/followers","following_url":"https://api.github.com/users/goldstar/following{/other_user}","gists_url":"https://api.github.com/users/goldstar/gists{/gist_id}","starred_url":"https://api.github.com/users/goldstar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goldstar/subscriptions","organizations_url":"https://api.github.com/users/goldstar/orgs","repos_url":"https://api.github.com/users/goldstar/repos","events_url":"https://api.github.com/users/goldstar/events{/privacy}","received_events_url":"https://api.github.com/users/goldstar/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/goldstar/blackbeard","description":"A Redis backed metrics collector with a Rack dashboard","fork":false,"url":"https://api.github.com/repos/goldstar/blackbeard","forks_url":"https://api.github.com/repos/goldstar/blackbeard/forks","keys_url":"https://api.github.com/repos/goldstar/blackbeard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/goldstar/blackbeard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/goldstar/blackbeard/teams","hooks_url":"https://api.github.com/repos/goldstar/blackbeard/hooks","issue_events_url":"https://api.github.com/repos/goldstar/blackbeard/issues/events{/number}","events_url":"https://api.github.com/repos/goldstar/blackbeard/events","assignees_url":"https://api.github.com/repos/goldstar/blackbeard/assignees{/user}","branches_url":"https://api.github.com/repos/goldstar/blackbeard/branches{/branch}","tags_url":"https://api.github.com/repos/goldstar/blackbeard/tags","blobs_url":"https://api.github.com/repos/goldstar/blackbeard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/goldstar/blackbeard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/goldstar/blackbeard/git/refs{/sha}","trees_url":"https://api.github.com/repos/goldstar/blackbeard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/goldstar/blackbeard/statuses/{sha}","languages_url":"https://api.github.com/repos/goldstar/blackbeard/languages","stargazers_url":"https://api.github.com/repos/goldstar/blackbeard/stargazers","contributors_url":"https://api.github.com/repos/goldstar/blackbeard/contributors","subscribers_url":"https://api.github.com/repos/goldstar/blackbeard/subscribers","subscription_url":"https://api.github.com/repos/goldstar/blackbeard/subscription","commits_url":"https://api.github.com/repos/goldstar/blackbeard/commits{/sha}","git_commits_url":"https://api.github.com/repos/goldstar/blackbeard/git/commits{/sha}","comments_url":"https://api.github.com/repos/goldstar/blackbeard/comments{/number}","issue_comment_url":"https://api.github.com/repos/goldstar/blackbeard/issues/comments{/number}","contents_url":"https://api.github.com/repos/goldstar/blackbeard/contents/{+path}","compare_url":"https://api.github.com/repos/goldstar/blackbeard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/goldstar/blackbeard/merges","archive_url":"https://api.github.com/repos/goldstar/blackbeard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/goldstar/blackbeard/downloads","issues_url":"https://api.github.com/repos/goldstar/blackbeard/issues{/number}","pulls_url":"https://api.github.com/repos/goldstar/blackbeard/pulls{/number}","milestones_url":"https://api.github.com/repos/goldstar/blackbeard/milestones{/number}","notifications_url":"https://api.github.com/repos/goldstar/blackbeard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/goldstar/blackbeard/labels{/name}","releases_url":"https://api.github.com/repos/goldstar/blackbeard/releases{/id}","created_at":"2014-01-16T00:58:05Z","updated_at":"2015-04-28T00:03:10Z","pushed_at":"2015-12-31T00:14:32Z","git_url":"git://github.com/goldstar/blackbeard.git","ssh_url":"git@github.com:goldstar/blackbeard.git","clone_url":"https://github.com/goldstar/blackbeard.git","svn_url":"https://github.com/goldstar/blackbeard","homepage":"","size":371,"stargazers_count":6,"watchers_count":6,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/goldstar/blackbeard/pulls/9"},"html":{"href":"https://github.com/goldstar/blackbeard/pull/9"},"issue":{"href":"https://api.github.com/repos/goldstar/blackbeard/issues/9"},"comments":{"href":"https://api.github.com/repos/goldstar/blackbeard/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/goldstar/blackbeard/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/goldstar/blackbeard/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/goldstar/blackbeard/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/goldstar/blackbeard/statuses/74addb6dd86567969e9e2f9ac71c440bd468dfb5"}}}}