{"action":"created","comment":{"url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/comments/26827093","id":26827093,"diff_hunk":"@@ -115,34 +115,47 @@ class PubSubHTTPEndpoint {\n       : value_name_(value_name),\n         http_request_(std::move(r)),\n         http_response_(http_request_.SendChunkedResponse()) {\n-    // TODO(dkorolev): `\"from\"`, etc.\n     if (http_request_.url.query.has(\"recent\")) {\n-      serving_ = false;\n+      serving_ = false;  // Start in 'non-serving' mode when `recent` is set.\n       from_timestamp_ =\n           r.timestamp - static_cast<bricks::time::MILLISECONDS_INTERVAL>(\n                             bricks::strings::FromString<uint64_t>(http_request_.url.query[\"recent\"]));\n-    } else {\n-      serving_ = true;\n     }\n-    n_ = http_request_.url.query.has(\"n\") ? bricks::strings::FromString<size_t>(http_request_.url.query[\"n\"])\n-                                          : 0;\n+    if (http_request_.url.query.has(\"n\")) {\n+      serving_ = false;  // Start in 'non-serving' mode when `n` is set.\n+      bricks::strings::FromString(http_request_.url.query[\"n\"], n_);\n+      cap_ = n_;  // If `?n=` parameter is set, it sets `cap_` too by default. Use `?n=...&cap=0` to override.\n+    }\n+    if (http_request_.url.query.has(\"n_min\")) {\n+      // `n_min` is same as `n`, but it does not set the cap; just the lower bound for `recent`.\n+      serving_ = false;  // Start in 'non-serving' mode when `n_min` is set.\n+      bricks::strings::FromString(http_request_.url.query[\"n_min\"], n_);\n+    }\n+    if (http_request_.url.query.has(\"cap\")) {\n+      bricks::strings::FromString(http_request_.url.query[\"cap\"], cap_);\n+    }\n   }\n \n-  inline bool Entry(E& entry) {\n+  inline bool Entry(E& entry, size_t index, size_t total) {\n     // TODO(dkorolev): Should we always extract the timestamp and throw an exception if there is a mismatch?\n     try {\n       if (!serving_) {\n-        // The only condition we have now to not serve the entries via HTTP is the `from` URL parameter.\n         const bricks::time::EPOCH_MILLISECONDS timestamp = ExtractTimestamp(entry);\n-        if (timestamp >= from_timestamp_) {\n+        // Respect `n`.\n+        if (total - index <= n_) {\n+          serving_ = true;\n+        }\n+        // Respect `recent`.\n+        if (from_timestamp_ != static_cast<bricks::time::EPOCH_MILLISECONDS>(-1) &&","path":"sherlock.h","position":53,"original_position":53,"commit_id":"a16bf3559b3483d7daf26e3b050bd9793fa3af4b","original_commit_id":"a16bf3559b3483d7daf26e3b050bd9793fa3af4b","user":{"login":"deathbaba","id":170263,"avatar_url":"https://avatars.githubusercontent.com/u/170263?v=3","gravatar_id":"","url":"https://api.github.com/users/deathbaba","html_url":"https://github.com/deathbaba","followers_url":"https://api.github.com/users/deathbaba/followers","following_url":"https://api.github.com/users/deathbaba/following{/other_user}","gists_url":"https://api.github.com/users/deathbaba/gists{/gist_id}","starred_url":"https://api.github.com/users/deathbaba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deathbaba/subscriptions","organizations_url":"https://api.github.com/users/deathbaba/orgs","repos_url":"https://api.github.com/users/deathbaba/repos","events_url":"https://api.github.com/users/deathbaba/events{/privacy}","received_events_url":"https://api.github.com/users/deathbaba/received_events","type":"User","site_admin":false},"body":"Use some time constant for invalid value?","created_at":"2015-03-20T09:29:55Z","updated_at":"2015-03-20T09:29:55Z","html_url":"https://github.com/KnowSheet/Sherlock/pull/10#discussion_r26827093","pull_request_url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/comments/26827093"},"html":{"href":"https://github.com/KnowSheet/Sherlock/pull/10#discussion_r26827093"},"pull_request":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/10","id":31593895,"html_url":"https://github.com/KnowSheet/Sherlock/pull/10","diff_url":"https://github.com/KnowSheet/Sherlock/pull/10.diff","patch_url":"https://github.com/KnowSheet/Sherlock/pull/10.patch","issue_url":"https://api.github.com/repos/KnowSheet/Sherlock/issues/10","number":10,"state":"open","locked":false,"title":"Proper `n` and `cap` URL PubSub parameters handling. Added `index` and `count` into the API.","user":{"login":"dkorolev","id":2159447,"avatar_url":"https://avatars.githubusercontent.com/u/2159447?v=3","gravatar_id":"","url":"https://api.github.com/users/dkorolev","html_url":"https://github.com/dkorolev","followers_url":"https://api.github.com/users/dkorolev/followers","following_url":"https://api.github.com/users/dkorolev/following{/other_user}","gists_url":"https://api.github.com/users/dkorolev/gists{/gist_id}","starred_url":"https://api.github.com/users/dkorolev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkorolev/subscriptions","organizations_url":"https://api.github.com/users/dkorolev/orgs","repos_url":"https://api.github.com/users/dkorolev/repos","events_url":"https://api.github.com/users/dkorolev/events{/privacy}","received_events_url":"https://api.github.com/users/dkorolev/received_events","type":"User","site_admin":false},"body":"CC @sompylasar, @mzhurovich.","created_at":"2015-03-20T07:47:37Z","updated_at":"2015-03-20T09:29:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"084f12b4f813ddd1194c62e8e27da7e466ff1078","assignee":{"login":"deathbaba","id":170263,"avatar_url":"https://avatars.githubusercontent.com/u/170263?v=3","gravatar_id":"","url":"https://api.github.com/users/deathbaba","html_url":"https://github.com/deathbaba","followers_url":"https://api.github.com/users/deathbaba/followers","following_url":"https://api.github.com/users/deathbaba/following{/other_user}","gists_url":"https://api.github.com/users/deathbaba/gists{/gist_id}","starred_url":"https://api.github.com/users/deathbaba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deathbaba/subscriptions","organizations_url":"https://api.github.com/users/deathbaba/orgs","repos_url":"https://api.github.com/users/deathbaba/repos","events_url":"https://api.github.com/users/deathbaba/events{/privacy}","received_events_url":"https://api.github.com/users/deathbaba/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/10/commits","review_comments_url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/10/comments","review_comment_url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/comments{/number}","comments_url":"https://api.github.com/repos/KnowSheet/Sherlock/issues/10/comments","statuses_url":"https://api.github.com/repos/KnowSheet/Sherlock/statuses/a16bf3559b3483d7daf26e3b050bd9793fa3af4b","head":{"label":"dkorolev:master","ref":"master","sha":"a16bf3559b3483d7daf26e3b050bd9793fa3af4b","user":{"login":"dkorolev","id":2159447,"avatar_url":"https://avatars.githubusercontent.com/u/2159447?v=3","gravatar_id":"","url":"https://api.github.com/users/dkorolev","html_url":"https://github.com/dkorolev","followers_url":"https://api.github.com/users/dkorolev/followers","following_url":"https://api.github.com/users/dkorolev/following{/other_user}","gists_url":"https://api.github.com/users/dkorolev/gists{/gist_id}","starred_url":"https://api.github.com/users/dkorolev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkorolev/subscriptions","organizations_url":"https://api.github.com/users/dkorolev/orgs","repos_url":"https://api.github.com/users/dkorolev/repos","events_url":"https://api.github.com/users/dkorolev/events{/privacy}","received_events_url":"https://api.github.com/users/dkorolev/received_events","type":"User","site_admin":false},"repo":{"id":31759731,"name":"Sherlock","full_name":"dkorolev/Sherlock","owner":{"login":"dkorolev","id":2159447,"avatar_url":"https://avatars.githubusercontent.com/u/2159447?v=3","gravatar_id":"","url":"https://api.github.com/users/dkorolev","html_url":"https://github.com/dkorolev","followers_url":"https://api.github.com/users/dkorolev/followers","following_url":"https://api.github.com/users/dkorolev/following{/other_user}","gists_url":"https://api.github.com/users/dkorolev/gists{/gist_id}","starred_url":"https://api.github.com/users/dkorolev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkorolev/subscriptions","organizations_url":"https://api.github.com/users/dkorolev/orgs","repos_url":"https://api.github.com/users/dkorolev/repos","events_url":"https://api.github.com/users/dkorolev/events{/privacy}","received_events_url":"https://api.github.com/users/dkorolev/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dkorolev/Sherlock","description":"Structured, append-only, immutable data persistence layer with publish-subscribe.","fork":true,"url":"https://api.github.com/repos/dkorolev/Sherlock","forks_url":"https://api.github.com/repos/dkorolev/Sherlock/forks","keys_url":"https://api.github.com/repos/dkorolev/Sherlock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dkorolev/Sherlock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dkorolev/Sherlock/teams","hooks_url":"https://api.github.com/repos/dkorolev/Sherlock/hooks","issue_events_url":"https://api.github.com/repos/dkorolev/Sherlock/issues/events{/number}","events_url":"https://api.github.com/repos/dkorolev/Sherlock/events","assignees_url":"https://api.github.com/repos/dkorolev/Sherlock/assignees{/user}","branches_url":"https://api.github.com/repos/dkorolev/Sherlock/branches{/branch}","tags_url":"https://api.github.com/repos/dkorolev/Sherlock/tags","blobs_url":"https://api.github.com/repos/dkorolev/Sherlock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dkorolev/Sherlock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dkorolev/Sherlock/git/refs{/sha}","trees_url":"https://api.github.com/repos/dkorolev/Sherlock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dkorolev/Sherlock/statuses/{sha}","languages_url":"https://api.github.com/repos/dkorolev/Sherlock/languages","stargazers_url":"https://api.github.com/repos/dkorolev/Sherlock/stargazers","contributors_url":"https://api.github.com/repos/dkorolev/Sherlock/contributors","subscribers_url":"https://api.github.com/repos/dkorolev/Sherlock/subscribers","subscription_url":"https://api.github.com/repos/dkorolev/Sherlock/subscription","commits_url":"https://api.github.com/repos/dkorolev/Sherlock/commits{/sha}","git_commits_url":"https://api.github.com/repos/dkorolev/Sherlock/git/commits{/sha}","comments_url":"https://api.github.com/repos/dkorolev/Sherlock/comments{/number}","issue_comment_url":"https://api.github.com/repos/dkorolev/Sherlock/issues/comments{/number}","contents_url":"https://api.github.com/repos/dkorolev/Sherlock/contents/{+path}","compare_url":"https://api.github.com/repos/dkorolev/Sherlock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dkorolev/Sherlock/merges","archive_url":"https://api.github.com/repos/dkorolev/Sherlock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dkorolev/Sherlock/downloads","issues_url":"https://api.github.com/repos/dkorolev/Sherlock/issues{/number}","pulls_url":"https://api.github.com/repos/dkorolev/Sherlock/pulls{/number}","milestones_url":"https://api.github.com/repos/dkorolev/Sherlock/milestones{/number}","notifications_url":"https://api.github.com/repos/dkorolev/Sherlock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dkorolev/Sherlock/labels{/name}","releases_url":"https://api.github.com/repos/dkorolev/Sherlock/releases{/id}","created_at":"2015-03-06T08:26:59Z","updated_at":"2015-03-20T07:57:43Z","pushed_at":"2015-03-20T07:57:43Z","git_url":"git://github.com/dkorolev/Sherlock.git","ssh_url":"git@github.com:dkorolev/Sherlock.git","clone_url":"https://github.com/dkorolev/Sherlock.git","svn_url":"https://github.com/dkorolev/Sherlock","homepage":null,"size":367,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"KnowSheet:master","ref":"master","sha":"25b528d0092372d90a04cb5f514c2eefe30e1250","user":{"login":"KnowSheet","id":9897562,"avatar_url":"https://avatars.githubusercontent.com/u/9897562?v=3","gravatar_id":"","url":"https://api.github.com/users/KnowSheet","html_url":"https://github.com/KnowSheet","followers_url":"https://api.github.com/users/KnowSheet/followers","following_url":"https://api.github.com/users/KnowSheet/following{/other_user}","gists_url":"https://api.github.com/users/KnowSheet/gists{/gist_id}","starred_url":"https://api.github.com/users/KnowSheet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KnowSheet/subscriptions","organizations_url":"https://api.github.com/users/KnowSheet/orgs","repos_url":"https://api.github.com/users/KnowSheet/repos","events_url":"https://api.github.com/users/KnowSheet/events{/privacy}","received_events_url":"https://api.github.com/users/KnowSheet/received_events","type":"Organization","site_admin":false},"repo":{"id":31759722,"name":"Sherlock","full_name":"KnowSheet/Sherlock","owner":{"login":"KnowSheet","id":9897562,"avatar_url":"https://avatars.githubusercontent.com/u/9897562?v=3","gravatar_id":"","url":"https://api.github.com/users/KnowSheet","html_url":"https://github.com/KnowSheet","followers_url":"https://api.github.com/users/KnowSheet/followers","following_url":"https://api.github.com/users/KnowSheet/following{/other_user}","gists_url":"https://api.github.com/users/KnowSheet/gists{/gist_id}","starred_url":"https://api.github.com/users/KnowSheet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KnowSheet/subscriptions","organizations_url":"https://api.github.com/users/KnowSheet/orgs","repos_url":"https://api.github.com/users/KnowSheet/repos","events_url":"https://api.github.com/users/KnowSheet/events{/privacy}","received_events_url":"https://api.github.com/users/KnowSheet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/KnowSheet/Sherlock","description":"Structured, append-only, immutable data persistence layer with publish-subscribe.","fork":false,"url":"https://api.github.com/repos/KnowSheet/Sherlock","forks_url":"https://api.github.com/repos/KnowSheet/Sherlock/forks","keys_url":"https://api.github.com/repos/KnowSheet/Sherlock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/KnowSheet/Sherlock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/KnowSheet/Sherlock/teams","hooks_url":"https://api.github.com/repos/KnowSheet/Sherlock/hooks","issue_events_url":"https://api.github.com/repos/KnowSheet/Sherlock/issues/events{/number}","events_url":"https://api.github.com/repos/KnowSheet/Sherlock/events","assignees_url":"https://api.github.com/repos/KnowSheet/Sherlock/assignees{/user}","branches_url":"https://api.github.com/repos/KnowSheet/Sherlock/branches{/branch}","tags_url":"https://api.github.com/repos/KnowSheet/Sherlock/tags","blobs_url":"https://api.github.com/repos/KnowSheet/Sherlock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/KnowSheet/Sherlock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/KnowSheet/Sherlock/git/refs{/sha}","trees_url":"https://api.github.com/repos/KnowSheet/Sherlock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/KnowSheet/Sherlock/statuses/{sha}","languages_url":"https://api.github.com/repos/KnowSheet/Sherlock/languages","stargazers_url":"https://api.github.com/repos/KnowSheet/Sherlock/stargazers","contributors_url":"https://api.github.com/repos/KnowSheet/Sherlock/contributors","subscribers_url":"https://api.github.com/repos/KnowSheet/Sherlock/subscribers","subscription_url":"https://api.github.com/repos/KnowSheet/Sherlock/subscription","commits_url":"https://api.github.com/repos/KnowSheet/Sherlock/commits{/sha}","git_commits_url":"https://api.github.com/repos/KnowSheet/Sherlock/git/commits{/sha}","comments_url":"https://api.github.com/repos/KnowSheet/Sherlock/comments{/number}","issue_comment_url":"https://api.github.com/repos/KnowSheet/Sherlock/issues/comments{/number}","contents_url":"https://api.github.com/repos/KnowSheet/Sherlock/contents/{+path}","compare_url":"https://api.github.com/repos/KnowSheet/Sherlock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/KnowSheet/Sherlock/merges","archive_url":"https://api.github.com/repos/KnowSheet/Sherlock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/KnowSheet/Sherlock/downloads","issues_url":"https://api.github.com/repos/KnowSheet/Sherlock/issues{/number}","pulls_url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls{/number}","milestones_url":"https://api.github.com/repos/KnowSheet/Sherlock/milestones{/number}","notifications_url":"https://api.github.com/repos/KnowSheet/Sherlock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/KnowSheet/Sherlock/labels{/name}","releases_url":"https://api.github.com/repos/KnowSheet/Sherlock/releases{/id}","created_at":"2015-03-06T08:26:50Z","updated_at":"2015-03-20T01:26:17Z","pushed_at":"2015-03-20T07:57:43Z","git_url":"git://github.com/KnowSheet/Sherlock.git","ssh_url":"git@github.com:KnowSheet/Sherlock.git","clone_url":"https://github.com/KnowSheet/Sherlock.git","svn_url":"https://github.com/KnowSheet/Sherlock","homepage":null,"size":425,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/10"},"html":{"href":"https://github.com/KnowSheet/Sherlock/pull/10"},"issue":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/issues/10"},"comments":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/statuses/a16bf3559b3483d7daf26e3b050bd9793fa3af4b"}}}}