{"action":"created","comment":{"url":"https://api.github.com/repos/letsencrypt/boulder/pulls/comments/40623054","id":40623054,"diff_hunk":"@@ -51,28 +102,70 @@ func setupClients(c cmd.Config, stats statsd.Statter) (rpc.CertificateAuthorityC\n \treturn cac, closeChan\n }\n \n-func (updater *OCSPUpdater) processResponse(tx *gorp.Transaction, serial string) error {\n-\tcertObj, err := tx.Get(core.Certificate{}, serial)\n-\tif err != nil {\n-\t\treturn err\n-\t}\n-\tstatusObj, err := tx.Get(core.CertificateStatus{}, serial)\n-\tif err != nil {\n-\t\treturn err\n+var errNoStaleResponses = errors.New(\"No stale responses to update\")\n+\n+func (updater *OCSPUpdater) findStaleOCSPResponses(oldestLastUpdatedTime time.Time, batchSize int) ([]core.Certificate, error) {\n+\tvar certs []core.Certificate\n+\t_, err := updater.dbMap.Select(\n+\t\t&certs,\n+\t\t`SELECT cert.*\n+\t\t FROM certificateStatus AS cs\n+\t\t JOIN certificates AS cert\n+\t\t ON cs.serial = cert.serial\n+\t\t WHERE cs.ocspLastUpdated < :lastUpdate\n+\t\t AND cert.expires > now()\n+\t\t ORDER BY cs.ocspLastUpdated ASC\n+\t\t LIMIT :limit`,\n+\t\tmap[string]interface{}{\n+\t\t\t\"lastUpdate\": oldestLastUpdatedTime,\n+\t\t\t\"limit\":      batchSize,\n+\t\t},\n+\t)\n+\tif err == sql.ErrNoRows || len(certs) == 0 {\n+\t\treturn certs, errNoStaleResponses\n \t}\n+\treturn certs, err\n+}\n \n-\tcert, ok := certObj.(*core.Certificate)\n-\tif !ok {\n-\t\treturn fmt.Errorf(\"Cast failure\")\n+var errNoNewCertificates = errors.New(\"No certificates issued since last check\")\n+\n+func (updater *OCSPUpdater) getCertificatesIssuedSince(since time.Time, batchSize int) ([]core.Certificate, error) {\n+\tvar certs []core.Certificate\n+\t_, err := updater.dbMap.Select(\n+\t\t&certs,\n+\t\t`SELECT * FROM certificates\n+\t\t WHERE issued > :since","path":"cmd/ocsp-updater/main.go","position":139,"original_position":139,"commit_id":"bf17e35f3576a67efd90fcdfd114be7aaa3d669a","original_commit_id":"bf17e35f3576a67efd90fcdfd114be7aaa3d669a","user":{"login":"jsha","id":220205,"avatar_url":"https://avatars.githubusercontent.com/u/220205?v=3","gravatar_id":"","url":"https://api.github.com/users/jsha","html_url":"https://github.com/jsha","followers_url":"https://api.github.com/users/jsha/followers","following_url":"https://api.github.com/users/jsha/following{/other_user}","gists_url":"https://api.github.com/users/jsha/gists{/gist_id}","starred_url":"https://api.github.com/users/jsha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsha/subscriptions","organizations_url":"https://api.github.com/users/jsha/orgs","repos_url":"https://api.github.com/users/jsha/repos","events_url":"https://api.github.com/users/jsha/events{/privacy}","received_events_url":"https://api.github.com/users/jsha/received_events","type":"User","site_admin":false},"body":"Here's a possibility: instead of checking the issued time, select over `certificateStatuses` and use `WHERE ocspLastUpdated = 0`. We would then need to add an index on `certificateStatuses.ocspLastUpdated`, and I think we would no longer need an index of `certificates.issued` (at least for now).\r\n\r\nThe initial zero value of OCSPLastUpdated is set in `sa.AddCertificate`, where it writes both the certificate and the certificateStatus value.","created_at":"2015-09-29T00:33:41Z","updated_at":"2015-09-29T00:33:41Z","html_url":"https://github.com/letsencrypt/boulder/pull/825#discussion_r40623054","pull_request_url":"https://api.github.com/repos/letsencrypt/boulder/pulls/825","_links":{"self":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/comments/40623054"},"html":{"href":"https://github.com/letsencrypt/boulder/pull/825#discussion_r40623054"},"pull_request":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/825"}}},"pull_request":{"url":"https://api.github.com/repos/letsencrypt/boulder/pulls/825","id":45622779,"html_url":"https://github.com/letsencrypt/boulder/pull/825","diff_url":"https://github.com/letsencrypt/boulder/pull/825.diff","patch_url":"https://github.com/letsencrypt/boulder/pull/825.patch","issue_url":"https://api.github.com/repos/letsencrypt/boulder/issues/825","number":825,"state":"open","locked":false,"title":"Daemonize OCSP updater and move first OCSP resp. generation","user":{"login":"rolandshoemaker","id":5080674,"avatar_url":"https://avatars.githubusercontent.com/u/5080674?v=3","gravatar_id":"","url":"https://api.github.com/users/rolandshoemaker","html_url":"https://github.com/rolandshoemaker","followers_url":"https://api.github.com/users/rolandshoemaker/followers","following_url":"https://api.github.com/users/rolandshoemaker/following{/other_user}","gists_url":"https://api.github.com/users/rolandshoemaker/gists{/gist_id}","starred_url":"https://api.github.com/users/rolandshoemaker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rolandshoemaker/subscriptions","organizations_url":"https://api.github.com/users/rolandshoemaker/orgs","repos_url":"https://api.github.com/users/rolandshoemaker/repos","events_url":"https://api.github.com/users/rolandshoemaker/events{/privacy}","received_events_url":"https://api.github.com/users/rolandshoemaker/received_events","type":"User","site_admin":false},"body":"First steps towards #828 #829.\r\n\r\nUpdates `github.com/jmhodges/clock` -- Tests OK\r\n\r\n```\r\n$ go test ./Godeps/_workspace/src/github.com/jmhodges/clock\r\nok  \tgithub.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/jmhodges/clock\t0.002s\r\n```","created_at":"2015-09-22T02:53:16Z","updated_at":"2015-09-29T00:33:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"64c0badf2edd97d63fbb76f3b0631adad8e3332e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/letsencrypt/boulder/pulls/825/commits","review_comments_url":"https://api.github.com/repos/letsencrypt/boulder/pulls/825/comments","review_comment_url":"https://api.github.com/repos/letsencrypt/boulder/pulls/comments{/number}","comments_url":"https://api.github.com/repos/letsencrypt/boulder/issues/825/comments","statuses_url":"https://api.github.com/repos/letsencrypt/boulder/statuses/bf17e35f3576a67efd90fcdfd114be7aaa3d669a","head":{"label":"letsencrypt:ocsp-collapse","ref":"ocsp-collapse","sha":"bf17e35f3576a67efd90fcdfd114be7aaa3d669a","user":{"login":"letsencrypt","id":9289019,"avatar_url":"https://avatars.githubusercontent.com/u/9289019?v=3","gravatar_id":"","url":"https://api.github.com/users/letsencrypt","html_url":"https://github.com/letsencrypt","followers_url":"https://api.github.com/users/letsencrypt/followers","following_url":"https://api.github.com/users/letsencrypt/following{/other_user}","gists_url":"https://api.github.com/users/letsencrypt/gists{/gist_id}","starred_url":"https://api.github.com/users/letsencrypt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/letsencrypt/subscriptions","organizations_url":"https://api.github.com/users/letsencrypt/orgs","repos_url":"https://api.github.com/users/letsencrypt/repos","events_url":"https://api.github.com/users/letsencrypt/events{/privacy}","received_events_url":"https://api.github.com/users/letsencrypt/received_events","type":"Organization","site_admin":false},"repo":{"id":28283593,"name":"boulder","full_name":"letsencrypt/boulder","owner":{"login":"letsencrypt","id":9289019,"avatar_url":"https://avatars.githubusercontent.com/u/9289019?v=3","gravatar_id":"","url":"https://api.github.com/users/letsencrypt","html_url":"https://github.com/letsencrypt","followers_url":"https://api.github.com/users/letsencrypt/followers","following_url":"https://api.github.com/users/letsencrypt/following{/other_user}","gists_url":"https://api.github.com/users/letsencrypt/gists{/gist_id}","starred_url":"https://api.github.com/users/letsencrypt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/letsencrypt/subscriptions","organizations_url":"https://api.github.com/users/letsencrypt/orgs","repos_url":"https://api.github.com/users/letsencrypt/repos","events_url":"https://api.github.com/users/letsencrypt/events{/privacy}","received_events_url":"https://api.github.com/users/letsencrypt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/letsencrypt/boulder","description":"An ACME-based CA, written in Go.","fork":false,"url":"https://api.github.com/repos/letsencrypt/boulder","forks_url":"https://api.github.com/repos/letsencrypt/boulder/forks","keys_url":"https://api.github.com/repos/letsencrypt/boulder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/letsencrypt/boulder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/letsencrypt/boulder/teams","hooks_url":"https://api.github.com/repos/letsencrypt/boulder/hooks","issue_events_url":"https://api.github.com/repos/letsencrypt/boulder/issues/events{/number}","events_url":"https://api.github.com/repos/letsencrypt/boulder/events","assignees_url":"https://api.github.com/repos/letsencrypt/boulder/assignees{/user}","branches_url":"https://api.github.com/repos/letsencrypt/boulder/branches{/branch}","tags_url":"https://api.github.com/repos/letsencrypt/boulder/tags","blobs_url":"https://api.github.com/repos/letsencrypt/boulder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/letsencrypt/boulder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/letsencrypt/boulder/git/refs{/sha}","trees_url":"https://api.github.com/repos/letsencrypt/boulder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/letsencrypt/boulder/statuses/{sha}","languages_url":"https://api.github.com/repos/letsencrypt/boulder/languages","stargazers_url":"https://api.github.com/repos/letsencrypt/boulder/stargazers","contributors_url":"https://api.github.com/repos/letsencrypt/boulder/contributors","subscribers_url":"https://api.github.com/repos/letsencrypt/boulder/subscribers","subscription_url":"https://api.github.com/repos/letsencrypt/boulder/subscription","commits_url":"https://api.github.com/repos/letsencrypt/boulder/commits{/sha}","git_commits_url":"https://api.github.com/repos/letsencrypt/boulder/git/commits{/sha}","comments_url":"https://api.github.com/repos/letsencrypt/boulder/comments{/number}","issue_comment_url":"https://api.github.com/repos/letsencrypt/boulder/issues/comments{/number}","contents_url":"https://api.github.com/repos/letsencrypt/boulder/contents/{+path}","compare_url":"https://api.github.com/repos/letsencrypt/boulder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/letsencrypt/boulder/merges","archive_url":"https://api.github.com/repos/letsencrypt/boulder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/letsencrypt/boulder/downloads","issues_url":"https://api.github.com/repos/letsencrypt/boulder/issues{/number}","pulls_url":"https://api.github.com/repos/letsencrypt/boulder/pulls{/number}","milestones_url":"https://api.github.com/repos/letsencrypt/boulder/milestones{/number}","notifications_url":"https://api.github.com/repos/letsencrypt/boulder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/letsencrypt/boulder/labels{/name}","releases_url":"https://api.github.com/repos/letsencrypt/boulder/releases{/id}","created_at":"2014-12-21T00:29:54Z","updated_at":"2015-09-27T17:20:59Z","pushed_at":"2015-09-28T23:30:57Z","git_url":"git://github.com/letsencrypt/boulder.git","ssh_url":"git@github.com:letsencrypt/boulder.git","clone_url":"https://github.com/letsencrypt/boulder.git","svn_url":"https://github.com/letsencrypt/boulder","homepage":null,"size":26640,"stargazers_count":710,"watchers_count":710,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":66,"mirror_url":null,"open_issues_count":148,"forks":66,"open_issues":148,"watchers":710,"default_branch":"master"}},"base":{"label":"letsencrypt:master","ref":"master","sha":"c9e8d1e23aedfc234603e155b4cd875cadcc7c0f","user":{"login":"letsencrypt","id":9289019,"avatar_url":"https://avatars.githubusercontent.com/u/9289019?v=3","gravatar_id":"","url":"https://api.github.com/users/letsencrypt","html_url":"https://github.com/letsencrypt","followers_url":"https://api.github.com/users/letsencrypt/followers","following_url":"https://api.github.com/users/letsencrypt/following{/other_user}","gists_url":"https://api.github.com/users/letsencrypt/gists{/gist_id}","starred_url":"https://api.github.com/users/letsencrypt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/letsencrypt/subscriptions","organizations_url":"https://api.github.com/users/letsencrypt/orgs","repos_url":"https://api.github.com/users/letsencrypt/repos","events_url":"https://api.github.com/users/letsencrypt/events{/privacy}","received_events_url":"https://api.github.com/users/letsencrypt/received_events","type":"Organization","site_admin":false},"repo":{"id":28283593,"name":"boulder","full_name":"letsencrypt/boulder","owner":{"login":"letsencrypt","id":9289019,"avatar_url":"https://avatars.githubusercontent.com/u/9289019?v=3","gravatar_id":"","url":"https://api.github.com/users/letsencrypt","html_url":"https://github.com/letsencrypt","followers_url":"https://api.github.com/users/letsencrypt/followers","following_url":"https://api.github.com/users/letsencrypt/following{/other_user}","gists_url":"https://api.github.com/users/letsencrypt/gists{/gist_id}","starred_url":"https://api.github.com/users/letsencrypt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/letsencrypt/subscriptions","organizations_url":"https://api.github.com/users/letsencrypt/orgs","repos_url":"https://api.github.com/users/letsencrypt/repos","events_url":"https://api.github.com/users/letsencrypt/events{/privacy}","received_events_url":"https://api.github.com/users/letsencrypt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/letsencrypt/boulder","description":"An ACME-based CA, written in Go.","fork":false,"url":"https://api.github.com/repos/letsencrypt/boulder","forks_url":"https://api.github.com/repos/letsencrypt/boulder/forks","keys_url":"https://api.github.com/repos/letsencrypt/boulder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/letsencrypt/boulder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/letsencrypt/boulder/teams","hooks_url":"https://api.github.com/repos/letsencrypt/boulder/hooks","issue_events_url":"https://api.github.com/repos/letsencrypt/boulder/issues/events{/number}","events_url":"https://api.github.com/repos/letsencrypt/boulder/events","assignees_url":"https://api.github.com/repos/letsencrypt/boulder/assignees{/user}","branches_url":"https://api.github.com/repos/letsencrypt/boulder/branches{/branch}","tags_url":"https://api.github.com/repos/letsencrypt/boulder/tags","blobs_url":"https://api.github.com/repos/letsencrypt/boulder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/letsencrypt/boulder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/letsencrypt/boulder/git/refs{/sha}","trees_url":"https://api.github.com/repos/letsencrypt/boulder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/letsencrypt/boulder/statuses/{sha}","languages_url":"https://api.github.com/repos/letsencrypt/boulder/languages","stargazers_url":"https://api.github.com/repos/letsencrypt/boulder/stargazers","contributors_url":"https://api.github.com/repos/letsencrypt/boulder/contributors","subscribers_url":"https://api.github.com/repos/letsencrypt/boulder/subscribers","subscription_url":"https://api.github.com/repos/letsencrypt/boulder/subscription","commits_url":"https://api.github.com/repos/letsencrypt/boulder/commits{/sha}","git_commits_url":"https://api.github.com/repos/letsencrypt/boulder/git/commits{/sha}","comments_url":"https://api.github.com/repos/letsencrypt/boulder/comments{/number}","issue_comment_url":"https://api.github.com/repos/letsencrypt/boulder/issues/comments{/number}","contents_url":"https://api.github.com/repos/letsencrypt/boulder/contents/{+path}","compare_url":"https://api.github.com/repos/letsencrypt/boulder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/letsencrypt/boulder/merges","archive_url":"https://api.github.com/repos/letsencrypt/boulder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/letsencrypt/boulder/downloads","issues_url":"https://api.github.com/repos/letsencrypt/boulder/issues{/number}","pulls_url":"https://api.github.com/repos/letsencrypt/boulder/pulls{/number}","milestones_url":"https://api.github.com/repos/letsencrypt/boulder/milestones{/number}","notifications_url":"https://api.github.com/repos/letsencrypt/boulder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/letsencrypt/boulder/labels{/name}","releases_url":"https://api.github.com/repos/letsencrypt/boulder/releases{/id}","created_at":"2014-12-21T00:29:54Z","updated_at":"2015-09-27T17:20:59Z","pushed_at":"2015-09-28T23:30:57Z","git_url":"git://github.com/letsencrypt/boulder.git","ssh_url":"git@github.com:letsencrypt/boulder.git","clone_url":"https://github.com/letsencrypt/boulder.git","svn_url":"https://github.com/letsencrypt/boulder","homepage":null,"size":26640,"stargazers_count":710,"watchers_count":710,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":66,"mirror_url":null,"open_issues_count":148,"forks":66,"open_issues":148,"watchers":710,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/825"},"html":{"href":"https://github.com/letsencrypt/boulder/pull/825"},"issue":{"href":"https://api.github.com/repos/letsencrypt/boulder/issues/825"},"comments":{"href":"https://api.github.com/repos/letsencrypt/boulder/issues/825/comments"},"review_comments":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/825/comments"},"review_comment":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/letsencrypt/boulder/pulls/825/commits"},"statuses":{"href":"https://api.github.com/repos/letsencrypt/boulder/statuses/bf17e35f3576a67efd90fcdfd114be7aaa3d669a"}}}}