{"action":"created","comment":{"url":"https://api.github.com/repos/hypothesis/h/pulls/comments/81092187","pull_request_review_id":2096743,"id":81092187,"diff_hunk":"@@ -61,26 +65,26 @@ def verify_ticket(self, principal, ticket_id):\n         if ticket_id is None:\n             return False\n \n-        # Since we load and then update the AuthTicket.expires on every request,\n-        # we optimise it with a `UPDATE ... RETURNING` query, doing both of\n-        # these in one. When the returned `userid` is `None` then the\n-        # authentication failed, otherwise it succeeded. Doing a query like this\n-        # will not mark the session as dirty, and thus the transaction will\n-        # get rolled back at the end, unless we found a userid, at which point\n-        # we manually mark the session as changed.\n-        ticket_query = (sa.update(AuthTicket.__table__)\n-                        .where(sa.and_(AuthTicket.id == ticket_id,\n-                                       AuthTicket.user_userid == principal,\n-                                       AuthTicket.expires > sa.func.now()))\n-                        .values(expires=(sa.func.now() + TICKET_TTL))\n-                        .returning(AuthTicket.user_userid))\n-        self._userid = self.session.execute(ticket_query).scalar()\n-\n-        if self._userid:\n-            mark_changed(self.session)\n-            return True\n-\n-        return False\n+        ticket = self.session.query(AuthTicket) \\\n+            .filter(AuthTicket.id == ticket_id,\n+                    AuthTicket.user_userid == principal,\n+                    AuthTicket.expires > sa.func.now()) \\\n+            .first()\n+\n+        if ticket is None:\n+            return False\n+\n+        self._userid = ticket.user_userid\n+\n+        # We don't want to update the `expires` column of an auth ticket on\n+        # every single request. So here we check that the difference would be\n+        # bigger than configured in the `NEW_EXPIRY_THRESHOLD` constant, and\n+        # only then update the auth ticket.\n+        new_expires = datetime.datetime.utcnow() + TICKET_TTL\n+        if (new_expires - ticket.expires) > NEW_EXPIRY_THRESHOLD:","path":"h/auth/services.py","position":59,"original_position":59,"commit_id":"be006391964591341c12bae5a385c3e7d65a4359","original_commit_id":"be006391964591341c12bae5a385c3e7d65a4359","user":{"login":"chdorner","id":112063,"avatar_url":"https://avatars.githubusercontent.com/u/112063?v=3","gravatar_id":"","url":"https://api.github.com/users/chdorner","html_url":"https://github.com/chdorner","followers_url":"https://api.github.com/users/chdorner/followers","following_url":"https://api.github.com/users/chdorner/following{/other_user}","gists_url":"https://api.github.com/users/chdorner/gists{/gist_id}","starred_url":"https://api.github.com/users/chdorner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chdorner/subscriptions","organizations_url":"https://api.github.com/users/chdorner/orgs","repos_url":"https://api.github.com/users/chdorner/repos","events_url":"https://api.github.com/users/chdorner/events{/privacy}","received_events_url":"https://api.github.com/users/chdorner/received_events","type":"User","site_admin":false},"body":"Sure, I was thinking of doing it like that, but decided against it in case the `updated` column gets updated due to another column getting changed?","created_at":"2016-09-29T08:58:32Z","updated_at":"2016-09-29T08:58:33Z","html_url":"https://github.com/hypothesis/h/pull/3947#discussion_r81092187","pull_request_url":"https://api.github.com/repos/hypothesis/h/pulls/3947","_links":{"self":{"href":"https://api.github.com/repos/hypothesis/h/pulls/comments/81092187"},"html":{"href":"https://github.com/hypothesis/h/pull/3947#discussion_r81092187"},"pull_request":{"href":"https://api.github.com/repos/hypothesis/h/pulls/3947"}}},"pull_request":{"url":"https://api.github.com/repos/hypothesis/h/pulls/3947","id":87141718,"html_url":"https://github.com/hypothesis/h/pull/3947","diff_url":"https://github.com/hypothesis/h/pull/3947.diff","patch_url":"https://github.com/hypothesis/h/pull/3947.patch","issue_url":"https://api.github.com/repos/hypothesis/h/issues/3947","number":3947,"state":"open","locked":false,"title":"Only update auth tickets expiry column after a threshold","user":{"login":"chdorner","id":112063,"avatar_url":"https://avatars.githubusercontent.com/u/112063?v=3","gravatar_id":"","url":"https://api.github.com/users/chdorner","html_url":"https://github.com/chdorner","followers_url":"https://api.github.com/users/chdorner/followers","following_url":"https://api.github.com/users/chdorner/following{/other_user}","gists_url":"https://api.github.com/users/chdorner/gists{/gist_id}","starred_url":"https://api.github.com/users/chdorner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chdorner/subscriptions","organizations_url":"https://api.github.com/users/chdorner/orgs","repos_url":"https://api.github.com/users/chdorner/repos","events_url":"https://api.github.com/users/chdorner/events{/privacy}","received_events_url":"https://api.github.com/users/chdorner/received_events","type":"User","site_admin":false},"body":"Before we did an `UPDATE ... RETURNING` query, which updated the auth\r\ntickets `expires` column on every single request. This can lead to\r\nlocking problems when one auth ticket is used in a lot of concurrent\r\nrequests. Which can lead to the `UPDATE ... RETURNING` query having to\r\nwait until the previous request has been finished and its transaction\r\ncommitted.\r\n\r\nThe proposed solution in this commit is to split this up into a `SELECT`\r\nquery for checking if the provided ticket is valid, then calculate the\r\nnew expiry date, but only set it if the current expiry date is older\r\nwith some additional threshold. This threshold is currently set at one\r\nminute.\r\n\r\nThis also has the effect that in the worst case that users can get\r\nlogged out after 6 days, 23 hours, and 59 minutes, instead of 7 days.\r\nThis difference however is small enough so that we can ignore it.","created_at":"2016-09-28T15:19:23Z","updated_at":"2016-09-29T08:58:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"af2f48318301801a570df30a0f35faca467e1f17","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/hypothesis/h/pulls/3947/commits","review_comments_url":"https://api.github.com/repos/hypothesis/h/pulls/3947/comments","review_comment_url":"https://api.github.com/repos/hypothesis/h/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hypothesis/h/issues/3947/comments","statuses_url":"https://api.github.com/repos/hypothesis/h/statuses/be006391964591341c12bae5a385c3e7d65a4359","head":{"label":"hypothesis:sporadically-increase-ticket-expiration","ref":"sporadically-increase-ticket-expiration","sha":"be006391964591341c12bae5a385c3e7d65a4359","user":{"login":"hypothesis","id":1243215,"avatar_url":"https://avatars.githubusercontent.com/u/1243215?v=3","gravatar_id":"","url":"https://api.github.com/users/hypothesis","html_url":"https://github.com/hypothesis","followers_url":"https://api.github.com/users/hypothesis/followers","following_url":"https://api.github.com/users/hypothesis/following{/other_user}","gists_url":"https://api.github.com/users/hypothesis/gists{/gist_id}","starred_url":"https://api.github.com/users/hypothesis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hypothesis/subscriptions","organizations_url":"https://api.github.com/users/hypothesis/orgs","repos_url":"https://api.github.com/users/hypothesis/repos","events_url":"https://api.github.com/users/hypothesis/events{/privacy}","received_events_url":"https://api.github.com/users/hypothesis/received_events","type":"Organization","site_admin":false},"repo":{"id":3910945,"name":"h","full_name":"hypothesis/h","owner":{"login":"hypothesis","id":1243215,"avatar_url":"https://avatars.githubusercontent.com/u/1243215?v=3","gravatar_id":"","url":"https://api.github.com/users/hypothesis","html_url":"https://github.com/hypothesis","followers_url":"https://api.github.com/users/hypothesis/followers","following_url":"https://api.github.com/users/hypothesis/following{/other_user}","gists_url":"https://api.github.com/users/hypothesis/gists{/gist_id}","starred_url":"https://api.github.com/users/hypothesis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hypothesis/subscriptions","organizations_url":"https://api.github.com/users/hypothesis/orgs","repos_url":"https://api.github.com/users/hypothesis/repos","events_url":"https://api.github.com/users/hypothesis/events{/privacy}","received_events_url":"https://api.github.com/users/hypothesis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hypothesis/h","description":"Annotate with anyone, anywhere.","fork":false,"url":"https://api.github.com/repos/hypothesis/h","forks_url":"https://api.github.com/repos/hypothesis/h/forks","keys_url":"https://api.github.com/repos/hypothesis/h/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hypothesis/h/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hypothesis/h/teams","hooks_url":"https://api.github.com/repos/hypothesis/h/hooks","issue_events_url":"https://api.github.com/repos/hypothesis/h/issues/events{/number}","events_url":"https://api.github.com/repos/hypothesis/h/events","assignees_url":"https://api.github.com/repos/hypothesis/h/assignees{/user}","branches_url":"https://api.github.com/repos/hypothesis/h/branches{/branch}","tags_url":"https://api.github.com/repos/hypothesis/h/tags","blobs_url":"https://api.github.com/repos/hypothesis/h/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hypothesis/h/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hypothesis/h/git/refs{/sha}","trees_url":"https://api.github.com/repos/hypothesis/h/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hypothesis/h/statuses/{sha}","languages_url":"https://api.github.com/repos/hypothesis/h/languages","stargazers_url":"https://api.github.com/repos/hypothesis/h/stargazers","contributors_url":"https://api.github.com/repos/hypothesis/h/contributors","subscribers_url":"https://api.github.com/repos/hypothesis/h/subscribers","subscription_url":"https://api.github.com/repos/hypothesis/h/subscription","commits_url":"https://api.github.com/repos/hypothesis/h/commits{/sha}","git_commits_url":"https://api.github.com/repos/hypothesis/h/git/commits{/sha}","comments_url":"https://api.github.com/repos/hypothesis/h/comments{/number}","issue_comment_url":"https://api.github.com/repos/hypothesis/h/issues/comments{/number}","contents_url":"https://api.github.com/repos/hypothesis/h/contents/{+path}","compare_url":"https://api.github.com/repos/hypothesis/h/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hypothesis/h/merges","archive_url":"https://api.github.com/repos/hypothesis/h/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hypothesis/h/downloads","issues_url":"https://api.github.com/repos/hypothesis/h/issues{/number}","pulls_url":"https://api.github.com/repos/hypothesis/h/pulls{/number}","milestones_url":"https://api.github.com/repos/hypothesis/h/milestones{/number}","notifications_url":"https://api.github.com/repos/hypothesis/h/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hypothesis/h/labels{/name}","releases_url":"https://api.github.com/repos/hypothesis/h/releases{/id}","deployments_url":"https://api.github.com/repos/hypothesis/h/deployments","created_at":"2012-04-02T19:56:59Z","updated_at":"2016-09-27T08:38:32Z","pushed_at":"2016-09-29T08:38:46Z","git_url":"git://github.com/hypothesis/h.git","ssh_url":"git@github.com:hypothesis/h.git","clone_url":"https://github.com/hypothesis/h.git","svn_url":"https://github.com/hypothesis/h","homepage":"https://hypothes.is/","size":31535,"stargazers_count":722,"watchers_count":722,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":157,"mirror_url":null,"open_issues_count":81,"forks":157,"open_issues":81,"watchers":722,"default_branch":"master"}},"base":{"label":"hypothesis:master","ref":"master","sha":"acad8b634b64b3e465c2f6de03c10315c2f7f46c","user":{"login":"hypothesis","id":1243215,"avatar_url":"https://avatars.githubusercontent.com/u/1243215?v=3","gravatar_id":"","url":"https://api.github.com/users/hypothesis","html_url":"https://github.com/hypothesis","followers_url":"https://api.github.com/users/hypothesis/followers","following_url":"https://api.github.com/users/hypothesis/following{/other_user}","gists_url":"https://api.github.com/users/hypothesis/gists{/gist_id}","starred_url":"https://api.github.com/users/hypothesis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hypothesis/subscriptions","organizations_url":"https://api.github.com/users/hypothesis/orgs","repos_url":"https://api.github.com/users/hypothesis/repos","events_url":"https://api.github.com/users/hypothesis/events{/privacy}","received_events_url":"https://api.github.com/users/hypothesis/received_events","type":"Organization","site_admin":false},"repo":{"id":3910945,"name":"h","full_name":"hypothesis/h","owner":{"login":"hypothesis","id":1243215,"avatar_url":"https://avatars.githubusercontent.com/u/1243215?v=3","gravatar_id":"","url":"https://api.github.com/users/hypothesis","html_url":"https://github.com/hypothesis","followers_url":"https://api.github.com/users/hypothesis/followers","following_url":"https://api.github.com/users/hypothesis/following{/other_user}","gists_url":"https://api.github.com/users/hypothesis/gists{/gist_id}","starred_url":"https://api.github.com/users/hypothesis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hypothesis/subscriptions","organizations_url":"https://api.github.com/users/hypothesis/orgs","repos_url":"https://api.github.com/users/hypothesis/repos","events_url":"https://api.github.com/users/hypothesis/events{/privacy}","received_events_url":"https://api.github.com/users/hypothesis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hypothesis/h","description":"Annotate with anyone, anywhere.","fork":false,"url":"https://api.github.com/repos/hypothesis/h","forks_url":"https://api.github.com/repos/hypothesis/h/forks","keys_url":"https://api.github.com/repos/hypothesis/h/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hypothesis/h/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hypothesis/h/teams","hooks_url":"https://api.github.com/repos/hypothesis/h/hooks","issue_events_url":"https://api.github.com/repos/hypothesis/h/issues/events{/number}","events_url":"https://api.github.com/repos/hypothesis/h/events","assignees_url":"https://api.github.com/repos/hypothesis/h/assignees{/user}","branches_url":"https://api.github.com/repos/hypothesis/h/branches{/branch}","tags_url":"https://api.github.com/repos/hypothesis/h/tags","blobs_url":"https://api.github.com/repos/hypothesis/h/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hypothesis/h/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hypothesis/h/git/refs{/sha}","trees_url":"https://api.github.com/repos/hypothesis/h/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hypothesis/h/statuses/{sha}","languages_url":"https://api.github.com/repos/hypothesis/h/languages","stargazers_url":"https://api.github.com/repos/hypothesis/h/stargazers","contributors_url":"https://api.github.com/repos/hypothesis/h/contributors","subscribers_url":"https://api.github.com/repos/hypothesis/h/subscribers","subscription_url":"https://api.github.com/repos/hypothesis/h/subscription","commits_url":"https://api.github.com/repos/hypothesis/h/commits{/sha}","git_commits_url":"https://api.github.com/repos/hypothesis/h/git/commits{/sha}","comments_url":"https://api.github.com/repos/hypothesis/h/comments{/number}","issue_comment_url":"https://api.github.com/repos/hypothesis/h/issues/comments{/number}","contents_url":"https://api.github.com/repos/hypothesis/h/contents/{+path}","compare_url":"https://api.github.com/repos/hypothesis/h/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hypothesis/h/merges","archive_url":"https://api.github.com/repos/hypothesis/h/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hypothesis/h/downloads","issues_url":"https://api.github.com/repos/hypothesis/h/issues{/number}","pulls_url":"https://api.github.com/repos/hypothesis/h/pulls{/number}","milestones_url":"https://api.github.com/repos/hypothesis/h/milestones{/number}","notifications_url":"https://api.github.com/repos/hypothesis/h/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hypothesis/h/labels{/name}","releases_url":"https://api.github.com/repos/hypothesis/h/releases{/id}","deployments_url":"https://api.github.com/repos/hypothesis/h/deployments","created_at":"2012-04-02T19:56:59Z","updated_at":"2016-09-27T08:38:32Z","pushed_at":"2016-09-29T08:38:46Z","git_url":"git://github.com/hypothesis/h.git","ssh_url":"git@github.com:hypothesis/h.git","clone_url":"https://github.com/hypothesis/h.git","svn_url":"https://github.com/hypothesis/h","homepage":"https://hypothes.is/","size":31535,"stargazers_count":722,"watchers_count":722,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":157,"mirror_url":null,"open_issues_count":81,"forks":157,"open_issues":81,"watchers":722,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hypothesis/h/pulls/3947"},"html":{"href":"https://github.com/hypothesis/h/pull/3947"},"issue":{"href":"https://api.github.com/repos/hypothesis/h/issues/3947"},"comments":{"href":"https://api.github.com/repos/hypothesis/h/issues/3947/comments"},"review_comments":{"href":"https://api.github.com/repos/hypothesis/h/pulls/3947/comments"},"review_comment":{"href":"https://api.github.com/repos/hypothesis/h/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hypothesis/h/pulls/3947/commits"},"statuses":{"href":"https://api.github.com/repos/hypothesis/h/statuses/be006391964591341c12bae5a385c3e7d65a4359"}}}}
{"actor":{"display_login":"chdorner"}}