{"action":"created","comment":{"url":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/comments/45410168","id":45410168,"diff_hunk":"@@ -373,16 +384,20 @@ public override long GetHashCount(string key)\n             if (key == null)\n                 throw new ArgumentNullException(\"key\");\n \n-            return AsyncHelper.RunSync(() =>\n-                _database.Hash.Find(Builders<HashDto>.Filter.Eq(_ => _.Key, key)).CountAsync());\n+            return AsyncHelper.RunSync(() => _database.Hash\n+                .Find(Builders<HashDto>.Filter.Eq(_ => _.Key, key))\n+                .CountAsync());\n         }\n \n         public override TimeSpan GetHashTtl(string key)\n         {\n             if (key == null) throw new ArgumentNullException(\"key\");\n \n-            List<HashDto> hashes = AsyncHelper.RunSync(() => _database.Hash.Find(Builders<HashDto>.Filter.Eq(_ => _.Key, key)).ToListAsync());\n-            DateTime? result = hashes.Any() ? hashes.Min(x => x.ExpireAt) : null;\n+            DateTime? result = AsyncHelper.RunSync(() => _database.Hash\n+                .Find(Builders<HashDto>.Filter.Eq(_ => _.Key, key))\n+                .SortBy(_ => _.ExpireAt)\n+                .Project(_ => _.ExpireAt)\n+                .FirstOrDefaultAsync());","path":"src/Hangfire.Mongo/MongoConnection.cs","position":129,"original_position":129,"commit_id":"208faf1cc9e9f8e6055c85d43f44b56dd3d4dfbc","original_commit_id":"13276e6aebbeebaf888087cb7fccff19985c5eb6","user":{"login":"tristal","id":2125841,"avatar_url":"https://avatars.githubusercontent.com/u/2125841?v=3","gravatar_id":"","url":"https://api.github.com/users/tristal","html_url":"https://github.com/tristal","followers_url":"https://api.github.com/users/tristal/followers","following_url":"https://api.github.com/users/tristal/following{/other_user}","gists_url":"https://api.github.com/users/tristal/gists{/gist_id}","starred_url":"https://api.github.com/users/tristal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tristal/subscriptions","organizations_url":"https://api.github.com/users/tristal/orgs","repos_url":"https://api.github.com/users/tristal/repos","events_url":"https://api.github.com/users/tristal/events{/privacy}","received_events_url":"https://api.github.com/users/tristal/received_events","type":"User","site_admin":false},"body":"This is an extension provided by the Mongo binaries.\r\n\r\n```\r\n    /// <summary>\r\n    /// Get the first result or null.\r\n    /// \r\n    /// </summary>\r\n    /// <param name=\"find\">The fluent find.</param><param name=\"cancellationToken\">The cancellation token.</param><typeparam name=\"TDocument\">The type of the document.</typeparam><typeparam name=\"TProjection\">The type of the projection (same as TDocument if there is no projection).</typeparam>\r\n    /// <returns>\r\n    /// A Task whose result is the first result or null.\r\n    /// </returns>\r\n    public static async Task<TProjection> FirstOrDefaultAsync<TDocument, TProjection>(this IFindFluent<TDocument, TProjection> find, CancellationToken cancellationToken = null)\r\n    {\r\n      Ensure.IsNotNull<IFindFluent<TDocument, TProjection>>(find, \"find\");\r\n      TProjection projection;\r\n      using (IAsyncCursor<TProjection> asyncCursor = await find.Limit(new int?(1)).ToCursorAsync(cancellationToken).ConfigureAwait(false))\r\n        projection = !await asyncCursor.MoveNextAsync(cancellationToken).ConfigureAwait(false) ? default (TProjection) : Enumerable.FirstOrDefault<TProjection>(asyncCursor.Current);\r\n      return projection;\r\n    }\r\n```","created_at":"2015-11-19T22:23:47Z","updated_at":"2015-11-19T22:23:47Z","html_url":"https://github.com/Trov/Hangfire.Mongo/pull/2#discussion_r45410168","pull_request_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/comments/45410168"},"html":{"href":"https://github.com/Trov/Hangfire.Mongo/pull/2#discussion_r45410168"},"pull_request":{"href":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/2","id":51218176,"html_url":"https://github.com/Trov/Hangfire.Mongo/pull/2","diff_url":"https://github.com/Trov/Hangfire.Mongo/pull/2.diff","patch_url":"https://github.com/Trov/Hangfire.Mongo/pull/2.patch","issue_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/issues/2","number":2,"state":"open","locked":false,"title":"Moving skip, limit and projection to be done mongo server side;","user":{"login":"tristal","id":2125841,"avatar_url":"https://avatars.githubusercontent.com/u/2125841?v=3","gravatar_id":"","url":"https://api.github.com/users/tristal","html_url":"https://github.com/tristal","followers_url":"https://api.github.com/users/tristal/followers","following_url":"https://api.github.com/users/tristal/following{/other_user}","gists_url":"https://api.github.com/users/tristal/gists{/gist_id}","starred_url":"https://api.github.com/users/tristal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tristal/subscriptions","organizations_url":"https://api.github.com/users/tristal/orgs","repos_url":"https://api.github.com/users/tristal/repos","events_url":"https://api.github.com/users/tristal/events{/privacy}","received_events_url":"https://api.github.com/users/tristal/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-19T12:51:39Z","updated_at":"2015-11-19T22:23:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eb7df390fd0a19ef120167ae3c9c9fa57a90bbc3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/2/commits","review_comments_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/2/comments","review_comment_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/issues/2/comments","statuses_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/statuses/208faf1cc9e9f8e6055c85d43f44b56dd3d4dfbc","head":{"label":"Trov:serverPerf","ref":"serverPerf","sha":"208faf1cc9e9f8e6055c85d43f44b56dd3d4dfbc","user":{"login":"Trov","id":2103808,"avatar_url":"https://avatars.githubusercontent.com/u/2103808?v=3","gravatar_id":"","url":"https://api.github.com/users/Trov","html_url":"https://github.com/Trov","followers_url":"https://api.github.com/users/Trov/followers","following_url":"https://api.github.com/users/Trov/following{/other_user}","gists_url":"https://api.github.com/users/Trov/gists{/gist_id}","starred_url":"https://api.github.com/users/Trov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Trov/subscriptions","organizations_url":"https://api.github.com/users/Trov/orgs","repos_url":"https://api.github.com/users/Trov/repos","events_url":"https://api.github.com/users/Trov/events{/privacy}","received_events_url":"https://api.github.com/users/Trov/received_events","type":"Organization","site_admin":false},"repo":{"id":46474079,"name":"Hangfire.Mongo","full_name":"Trov/Hangfire.Mongo","owner":{"login":"Trov","id":2103808,"avatar_url":"https://avatars.githubusercontent.com/u/2103808?v=3","gravatar_id":"","url":"https://api.github.com/users/Trov","html_url":"https://github.com/Trov","followers_url":"https://api.github.com/users/Trov/followers","following_url":"https://api.github.com/users/Trov/following{/other_user}","gists_url":"https://api.github.com/users/Trov/gists{/gist_id}","starred_url":"https://api.github.com/users/Trov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Trov/subscriptions","organizations_url":"https://api.github.com/users/Trov/orgs","repos_url":"https://api.github.com/users/Trov/repos","events_url":"https://api.github.com/users/Trov/events{/privacy}","received_events_url":"https://api.github.com/users/Trov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Trov/Hangfire.Mongo","description":"Mongo DB support for Hangfire","fork":true,"url":"https://api.github.com/repos/Trov/Hangfire.Mongo","forks_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/forks","keys_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/teams","hooks_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/hooks","issue_events_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/issues/events{/number}","events_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/events","assignees_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/assignees{/user}","branches_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/branches{/branch}","tags_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/tags","blobs_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/git/refs{/sha}","trees_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/statuses/{sha}","languages_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/languages","stargazers_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/stargazers","contributors_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/contributors","subscribers_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/subscribers","subscription_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/subscription","commits_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/commits{/sha}","git_commits_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/git/commits{/sha}","comments_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/comments{/number}","issue_comment_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/issues/comments{/number}","contents_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/contents/{+path}","compare_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/merges","archive_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/downloads","issues_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/issues{/number}","pulls_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls{/number}","milestones_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/milestones{/number}","notifications_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/labels{/name}","releases_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/releases{/id}","created_at":"2015-11-19T07:00:02Z","updated_at":"2015-11-19T07:00:03Z","pushed_at":"2015-11-19T22:21:50Z","git_url":"git://github.com/Trov/Hangfire.Mongo.git","ssh_url":"git@github.com:Trov/Hangfire.Mongo.git","clone_url":"https://github.com/Trov/Hangfire.Mongo.git","svn_url":"https://github.com/Trov/Hangfire.Mongo","homepage":null,"size":1099,"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":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"Trov:master","ref":"master","sha":"bb7e40806e2714eb5460d7c8dccc5b0b2c4dadc8","user":{"login":"Trov","id":2103808,"avatar_url":"https://avatars.githubusercontent.com/u/2103808?v=3","gravatar_id":"","url":"https://api.github.com/users/Trov","html_url":"https://github.com/Trov","followers_url":"https://api.github.com/users/Trov/followers","following_url":"https://api.github.com/users/Trov/following{/other_user}","gists_url":"https://api.github.com/users/Trov/gists{/gist_id}","starred_url":"https://api.github.com/users/Trov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Trov/subscriptions","organizations_url":"https://api.github.com/users/Trov/orgs","repos_url":"https://api.github.com/users/Trov/repos","events_url":"https://api.github.com/users/Trov/events{/privacy}","received_events_url":"https://api.github.com/users/Trov/received_events","type":"Organization","site_admin":false},"repo":{"id":46474079,"name":"Hangfire.Mongo","full_name":"Trov/Hangfire.Mongo","owner":{"login":"Trov","id":2103808,"avatar_url":"https://avatars.githubusercontent.com/u/2103808?v=3","gravatar_id":"","url":"https://api.github.com/users/Trov","html_url":"https://github.com/Trov","followers_url":"https://api.github.com/users/Trov/followers","following_url":"https://api.github.com/users/Trov/following{/other_user}","gists_url":"https://api.github.com/users/Trov/gists{/gist_id}","starred_url":"https://api.github.com/users/Trov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Trov/subscriptions","organizations_url":"https://api.github.com/users/Trov/orgs","repos_url":"https://api.github.com/users/Trov/repos","events_url":"https://api.github.com/users/Trov/events{/privacy}","received_events_url":"https://api.github.com/users/Trov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Trov/Hangfire.Mongo","description":"Mongo DB support for Hangfire","fork":true,"url":"https://api.github.com/repos/Trov/Hangfire.Mongo","forks_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/forks","keys_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/teams","hooks_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/hooks","issue_events_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/issues/events{/number}","events_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/events","assignees_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/assignees{/user}","branches_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/branches{/branch}","tags_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/tags","blobs_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/git/refs{/sha}","trees_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/statuses/{sha}","languages_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/languages","stargazers_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/stargazers","contributors_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/contributors","subscribers_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/subscribers","subscription_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/subscription","commits_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/commits{/sha}","git_commits_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/git/commits{/sha}","comments_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/comments{/number}","issue_comment_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/issues/comments{/number}","contents_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/contents/{+path}","compare_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/merges","archive_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/downloads","issues_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/issues{/number}","pulls_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls{/number}","milestones_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/milestones{/number}","notifications_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/labels{/name}","releases_url":"https://api.github.com/repos/Trov/Hangfire.Mongo/releases{/id}","created_at":"2015-11-19T07:00:02Z","updated_at":"2015-11-19T07:00:03Z","pushed_at":"2015-11-19T22:21:50Z","git_url":"git://github.com/Trov/Hangfire.Mongo.git","ssh_url":"git@github.com:Trov/Hangfire.Mongo.git","clone_url":"https://github.com/Trov/Hangfire.Mongo.git","svn_url":"https://github.com/Trov/Hangfire.Mongo","homepage":null,"size":1099,"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":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/2"},"html":{"href":"https://github.com/Trov/Hangfire.Mongo/pull/2"},"issue":{"href":"https://api.github.com/repos/Trov/Hangfire.Mongo/issues/2"},"comments":{"href":"https://api.github.com/repos/Trov/Hangfire.Mongo/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Trov/Hangfire.Mongo/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/Trov/Hangfire.Mongo/statuses/208faf1cc9e9f8e6055c85d43f44b56dd3d4dfbc"}}}}