{"action":"created","comment":{"url":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/comments/41328466","id":41328466,"diff_hunk":"@@ -733,3 +738,85 @@ pledgeStatus uid = do\n     return $ case underfunded of\n         [] -> AllFunded\n         _ -> ExistsUnderfunded\n+\n+\n+claimedTickets :: UserId -> Handler [(Entity Ticket, Maybe (Entity WikiTarget), Import.Value Text)]\n+claimedTickets user_id = do\n+\n+    -- TODO: abstract out grabbing the project\n+    runDB $ select $ from $ \\(c `InnerJoin` t `InnerJoin` tc `LeftOuterJoin` wp `LeftOuterJoin` wt `InnerJoin` p) -> do\n+        on_ $ p ^. ProjectDiscussion ==. c ^. CommentDiscussion ||. wp ?. WikiPageProject ==. just (p ^. ProjectId)\n+        on_ $ wt ?. WikiTargetPage ==. wp ?. WikiPageId\n+        on_ $ wp ?. WikiPageDiscussion ==. just (c ^. CommentDiscussion)\n+        on_ $ tc ^. TicketClaimingTicket ==. c ^. CommentId\n+        on_ $ t ^. TicketComment ==. c ^. CommentId\n+\n+        where_ $ tc ^. TicketClaimingUser ==. val user_id\n+            &&. c ^. CommentId `notIn` (subList_select $ from $ return . (^. CommentClosingComment))\n+            &&. c ^. CommentId `notIn` (subList_select $ from $ return . (^. CommentRethreadOldComment))\n+\n+        orderBy [ asc $ tc ^. TicketClaimingTs ]\n+\n+        return (t, wt, p ^. ProjectHandle)\n+\n+    -- XXX: There are two known issues with this query:\n+    -- 1. If a watched comment is a ticket and the nth child, the\n+    -- query will return the same ticket n times.\n+    -- 2. If there are n watched comments in the same thread, each\n+    -- child ticket in the thread will be returned n times.\n+    -- 'select . distinct' just hides these problems from the user's\n+    -- eyes.\n+\n+countClaimedTickets :: UserId -> Handler Int\n+countClaimedTickets user_id = do\n+\n+    claimed_tickets <- claimedTickets user_id\n+    return $ length claimed_tickets\n+\n+countWatchedTickets :: UserId -> Handler Int\n+countWatchedTickets user_id = do\n+\n+    watched_tickets <- watchedTickets user_id\n+    return $ length watched_tickets\n+\n+countTickets :: UserId -> Handler Int\n+countTickets user_id = do\n+\n+    claimed_tickets <- claimedTickets user_id\n+    watched_tickets <- watchedTickets user_id\n+    return $ (length watched_tickets) + (length claimed_tickets)","path":"src/Model/User.hs","position":69,"original_position":69,"commit_id":"8be4212da33d23cf47bb404951aa3218a5df6f7d","original_commit_id":"8be4212da33d23cf47bb404951aa3218a5df6f7d","user":{"login":"chreekat","id":538538,"avatar_url":"https://avatars.githubusercontent.com/u/538538?v=3","gravatar_id":"","url":"https://api.github.com/users/chreekat","html_url":"https://github.com/chreekat","followers_url":"https://api.github.com/users/chreekat/followers","following_url":"https://api.github.com/users/chreekat/following{/other_user}","gists_url":"https://api.github.com/users/chreekat/gists{/gist_id}","starred_url":"https://api.github.com/users/chreekat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chreekat/subscriptions","organizations_url":"https://api.github.com/users/chreekat/orgs","repos_url":"https://api.github.com/users/chreekat/repos","events_url":"https://api.github.com/users/chreekat/events{/privacy}","received_events_url":"https://api.github.com/users/chreekat/received_events","type":"User","site_admin":false},"body":"I'm almost certain it's implemented incorrectly. I'm actually just going to take the combined-count feature out. (Note this line note is specifically talking about `countTickets`, not any other methods). Implementing it would just layer on some more complications on top of too-complicated code.","created_at":"2015-10-06T22:00:17Z","updated_at":"2015-10-06T22:00:17Z","html_url":"https://github.com/snowdriftcoop/snowdrift/pull/325#discussion_r41328466","pull_request_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/325","_links":{"self":{"href":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/comments/41328466"},"html":{"href":"https://github.com/snowdriftcoop/snowdrift/pull/325#discussion_r41328466"},"pull_request":{"href":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/325"}}},"pull_request":{"url":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/325","id":46715638,"html_url":"https://github.com/snowdriftcoop/snowdrift/pull/325","diff_url":"https://github.com/snowdriftcoop/snowdrift/pull/325.diff","patch_url":"https://github.com/snowdriftcoop/snowdrift/pull/325.patch","issue_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/issues/325","number":325,"state":"open","locked":false,"title":"abstract ticket counting to user model","user":{"login":"hollocherdale","id":6012572,"avatar_url":"https://avatars.githubusercontent.com/u/6012572?v=3","gravatar_id":"","url":"https://api.github.com/users/hollocherdale","html_url":"https://github.com/hollocherdale","followers_url":"https://api.github.com/users/hollocherdale/followers","following_url":"https://api.github.com/users/hollocherdale/following{/other_user}","gists_url":"https://api.github.com/users/hollocherdale/gists{/gist_id}","starred_url":"https://api.github.com/users/hollocherdale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hollocherdale/subscriptions","organizations_url":"https://api.github.com/users/hollocherdale/orgs","repos_url":"https://api.github.com/users/hollocherdale/repos","events_url":"https://api.github.com/users/hollocherdale/events{/privacy}","received_events_url":"https://api.github.com/users/hollocherdale/received_events","type":"User","site_admin":false},"body":"aaron helped out with this. We took the ticket counting out of the handler so that it can be simply called on the user page. Not sure if this was the best approach.","created_at":"2015-10-03T23:29:55Z","updated_at":"2015-10-06T22:00:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"587f26035d5ba903fe7e4db13079f366560ba9da","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/325/commits","review_comments_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/325/comments","review_comment_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/comments{/number}","comments_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/issues/325/comments","statuses_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/statuses/8be4212da33d23cf47bb404951aa3218a5df6f7d","head":{"label":"hollocherdale:ticket-counts","ref":"ticket-counts","sha":"8be4212da33d23cf47bb404951aa3218a5df6f7d","user":{"login":"hollocherdale","id":6012572,"avatar_url":"https://avatars.githubusercontent.com/u/6012572?v=3","gravatar_id":"","url":"https://api.github.com/users/hollocherdale","html_url":"https://github.com/hollocherdale","followers_url":"https://api.github.com/users/hollocherdale/followers","following_url":"https://api.github.com/users/hollocherdale/following{/other_user}","gists_url":"https://api.github.com/users/hollocherdale/gists{/gist_id}","starred_url":"https://api.github.com/users/hollocherdale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hollocherdale/subscriptions","organizations_url":"https://api.github.com/users/hollocherdale/orgs","repos_url":"https://api.github.com/users/hollocherdale/repos","events_url":"https://api.github.com/users/hollocherdale/events{/privacy}","received_events_url":"https://api.github.com/users/hollocherdale/received_events","type":"User","site_admin":false},"repo":{"id":41173849,"name":"snowdrift","full_name":"hollocherdale/snowdrift","owner":{"login":"hollocherdale","id":6012572,"avatar_url":"https://avatars.githubusercontent.com/u/6012572?v=3","gravatar_id":"","url":"https://api.github.com/users/hollocherdale","html_url":"https://github.com/hollocherdale","followers_url":"https://api.github.com/users/hollocherdale/followers","following_url":"https://api.github.com/users/hollocherdale/following{/other_user}","gists_url":"https://api.github.com/users/hollocherdale/gists{/gist_id}","starred_url":"https://api.github.com/users/hollocherdale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hollocherdale/subscriptions","organizations_url":"https://api.github.com/users/hollocherdale/orgs","repos_url":"https://api.github.com/users/hollocherdale/repos","events_url":"https://api.github.com/users/hollocherdale/events{/privacy}","received_events_url":"https://api.github.com/users/hollocherdale/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hollocherdale/snowdrift","description":"Infrastructure for Snowdrift.coop","fork":true,"url":"https://api.github.com/repos/hollocherdale/snowdrift","forks_url":"https://api.github.com/repos/hollocherdale/snowdrift/forks","keys_url":"https://api.github.com/repos/hollocherdale/snowdrift/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hollocherdale/snowdrift/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hollocherdale/snowdrift/teams","hooks_url":"https://api.github.com/repos/hollocherdale/snowdrift/hooks","issue_events_url":"https://api.github.com/repos/hollocherdale/snowdrift/issues/events{/number}","events_url":"https://api.github.com/repos/hollocherdale/snowdrift/events","assignees_url":"https://api.github.com/repos/hollocherdale/snowdrift/assignees{/user}","branches_url":"https://api.github.com/repos/hollocherdale/snowdrift/branches{/branch}","tags_url":"https://api.github.com/repos/hollocherdale/snowdrift/tags","blobs_url":"https://api.github.com/repos/hollocherdale/snowdrift/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hollocherdale/snowdrift/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hollocherdale/snowdrift/git/refs{/sha}","trees_url":"https://api.github.com/repos/hollocherdale/snowdrift/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hollocherdale/snowdrift/statuses/{sha}","languages_url":"https://api.github.com/repos/hollocherdale/snowdrift/languages","stargazers_url":"https://api.github.com/repos/hollocherdale/snowdrift/stargazers","contributors_url":"https://api.github.com/repos/hollocherdale/snowdrift/contributors","subscribers_url":"https://api.github.com/repos/hollocherdale/snowdrift/subscribers","subscription_url":"https://api.github.com/repos/hollocherdale/snowdrift/subscription","commits_url":"https://api.github.com/repos/hollocherdale/snowdrift/commits{/sha}","git_commits_url":"https://api.github.com/repos/hollocherdale/snowdrift/git/commits{/sha}","comments_url":"https://api.github.com/repos/hollocherdale/snowdrift/comments{/number}","issue_comment_url":"https://api.github.com/repos/hollocherdale/snowdrift/issues/comments{/number}","contents_url":"https://api.github.com/repos/hollocherdale/snowdrift/contents/{+path}","compare_url":"https://api.github.com/repos/hollocherdale/snowdrift/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hollocherdale/snowdrift/merges","archive_url":"https://api.github.com/repos/hollocherdale/snowdrift/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hollocherdale/snowdrift/downloads","issues_url":"https://api.github.com/repos/hollocherdale/snowdrift/issues{/number}","pulls_url":"https://api.github.com/repos/hollocherdale/snowdrift/pulls{/number}","milestones_url":"https://api.github.com/repos/hollocherdale/snowdrift/milestones{/number}","notifications_url":"https://api.github.com/repos/hollocherdale/snowdrift/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hollocherdale/snowdrift/labels{/name}","releases_url":"https://api.github.com/repos/hollocherdale/snowdrift/releases{/id}","created_at":"2015-08-21T19:34:05Z","updated_at":"2015-08-21T19:34:06Z","pushed_at":"2015-10-03T23:27:53Z","git_url":"git://github.com/hollocherdale/snowdrift.git","ssh_url":"git@github.com:hollocherdale/snowdrift.git","clone_url":"https://github.com/hollocherdale/snowdrift.git","svn_url":"https://github.com/hollocherdale/snowdrift","homepage":null,"size":15931,"stargazers_count":0,"watchers_count":0,"language":"Haskell","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"snowdriftcoop:master","ref":"master","sha":"95d55de7c3afb9a37191d62b9bc545a7bf5e27bc","user":{"login":"snowdriftcoop","id":6138345,"avatar_url":"https://avatars.githubusercontent.com/u/6138345?v=3","gravatar_id":"","url":"https://api.github.com/users/snowdriftcoop","html_url":"https://github.com/snowdriftcoop","followers_url":"https://api.github.com/users/snowdriftcoop/followers","following_url":"https://api.github.com/users/snowdriftcoop/following{/other_user}","gists_url":"https://api.github.com/users/snowdriftcoop/gists{/gist_id}","starred_url":"https://api.github.com/users/snowdriftcoop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snowdriftcoop/subscriptions","organizations_url":"https://api.github.com/users/snowdriftcoop/orgs","repos_url":"https://api.github.com/users/snowdriftcoop/repos","events_url":"https://api.github.com/users/snowdriftcoop/events{/privacy}","received_events_url":"https://api.github.com/users/snowdriftcoop/received_events","type":"Organization","site_admin":false},"repo":{"id":6098283,"name":"snowdrift","full_name":"snowdriftcoop/snowdrift","owner":{"login":"snowdriftcoop","id":6138345,"avatar_url":"https://avatars.githubusercontent.com/u/6138345?v=3","gravatar_id":"","url":"https://api.github.com/users/snowdriftcoop","html_url":"https://github.com/snowdriftcoop","followers_url":"https://api.github.com/users/snowdriftcoop/followers","following_url":"https://api.github.com/users/snowdriftcoop/following{/other_user}","gists_url":"https://api.github.com/users/snowdriftcoop/gists{/gist_id}","starred_url":"https://api.github.com/users/snowdriftcoop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snowdriftcoop/subscriptions","organizations_url":"https://api.github.com/users/snowdriftcoop/orgs","repos_url":"https://api.github.com/users/snowdriftcoop/repos","events_url":"https://api.github.com/users/snowdriftcoop/events{/privacy}","received_events_url":"https://api.github.com/users/snowdriftcoop/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/snowdriftcoop/snowdrift","description":"Infrastructure for Snowdrift.coop","fork":false,"url":"https://api.github.com/repos/snowdriftcoop/snowdrift","forks_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/forks","keys_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/keys{/key_id}","collaborators_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/teams","hooks_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/hooks","issue_events_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/issues/events{/number}","events_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/events","assignees_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/assignees{/user}","branches_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/branches{/branch}","tags_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/tags","blobs_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/git/refs{/sha}","trees_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/git/trees{/sha}","statuses_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/statuses/{sha}","languages_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/languages","stargazers_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/stargazers","contributors_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/contributors","subscribers_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/subscribers","subscription_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/subscription","commits_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/commits{/sha}","git_commits_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/git/commits{/sha}","comments_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/comments{/number}","issue_comment_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/issues/comments{/number}","contents_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/contents/{+path}","compare_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/compare/{base}...{head}","merges_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/merges","archive_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/downloads","issues_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/issues{/number}","pulls_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls{/number}","milestones_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/milestones{/number}","notifications_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/labels{/name}","releases_url":"https://api.github.com/repos/snowdriftcoop/snowdrift/releases{/id}","created_at":"2012-10-06T00:02:35Z","updated_at":"2015-08-03T09:20:09Z","pushed_at":"2015-10-06T21:44:49Z","git_url":"git://github.com/snowdriftcoop/snowdrift.git","ssh_url":"git@github.com:snowdriftcoop/snowdrift.git","clone_url":"https://github.com/snowdriftcoop/snowdrift.git","svn_url":"https://github.com/snowdriftcoop/snowdrift","homepage":null,"size":18678,"stargazers_count":45,"watchers_count":45,"language":"Haskell","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":54,"forks":31,"open_issues":54,"watchers":45,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/325"},"html":{"href":"https://github.com/snowdriftcoop/snowdrift/pull/325"},"issue":{"href":"https://api.github.com/repos/snowdriftcoop/snowdrift/issues/325"},"comments":{"href":"https://api.github.com/repos/snowdriftcoop/snowdrift/issues/325/comments"},"review_comments":{"href":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/325/comments"},"review_comment":{"href":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/snowdriftcoop/snowdrift/pulls/325/commits"},"statuses":{"href":"https://api.github.com/repos/snowdriftcoop/snowdrift/statuses/8be4212da33d23cf47bb404951aa3218a5df6f7d"}}}}