{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/32233277","id":32233277,"diff_hunk":"@@ -0,0 +1,130 @@\n+// source: util/querycache.ts\n+/// <reference path=\"../typings/mithriljs/mithril.d.ts\" />\n+// Author: Matt Tracy (matt@cockroachlabs.com)\n+//\n+module Utils {\n+    import promise = _mithril.MithrilPromise;\n+    import property = _mithril.MithrilProperty;\n+\n+    /**\n+     * QueryCache supports caching the result of an arbitrary query so that the\n+     * result of that query can be shared by multiple components.\n+     *\n+     * The initial state of the QueryCache will have no data; the query function\n+     * will be called immediately when the QueryCache is constructed, but data\n+     * will not yet be available. When the query completes, the QueryCache will\n+     * contain either the result of the Query or an Error that resulted from the\n+     * Query.\n+     *\n+     * The QueryCache can be refreshed at any time, which will re-issue the same\n+     * query and replace the cached value. The original cache value will not be\n+     * replaced until the new query completes. Each time the query is refreshed,\n+     * the value of QueryCache.epoch() is increased.\n+     */\n+    export class QueryCache<T> {\n+        private _result:T = null;\n+        private _error:Error = null;\n+        private _epoch:number = 0;\n+\n+        /**\n+         * Construct a new QueryCache which caches the ultimate results of the\n+         * given query function. It is expected that the query function returns\n+         * a promise for results.\n+         */\n+        constructor(private _query:() => promise<T>) {\n+            this.refresh()\n+        }\n+            \n+        /**\n+         * Refresh invokes the underlying query function, unless another\n+         * invocation is already in progress. The currently cached results (if\n+         * any) are not replaced until the query invocation completes.\n+         */\n+        refresh() {\n+            // Clear outstanding result if it has already returned.\n+            this.processOutstanding();\n+            if (!this._outstanding) {\n+                this._outstanding = {\n+                    result:this._query(),\n+                    error:m.prop(<Error> null), \n+                }\n+                this._outstanding.result.then(null, this._outstanding.error);\n+            }\n+        }\n+\n+        /**\n+         * setQuery replaces the query function underlying this QueryCache.\n+         */\n+        setQuery(q:() => promise<T>) {\n+            this._query = q;\n+        }\n+\n+        /**\n+         * hasData returns true if at least one query has completed. This\n+         * indicates that either the result() or error() functions will return\n+         * non-null.\n+         */\n+        hasData():boolean {\n+            this.processOutstanding();\n+            return this._epoch > 0;\n+        }\n+\n+        /**\n+         * result returns the result of most recent invocation of the underlying\n+         * query. If the most recent invocation returned an error, this method will\n+         * return null.\n+         */\n+        result():T {\n+            this.processOutstanding();\n+            return this._result;\n+        }\n+\n+        /**\n+         * result returns any error that resulted from the most recent\n+         * invocation of the underlying query. If the most recent invocation did\n+         * not return an error, this method will return null.\n+         */\n+        error():Error {\n+            this.processOutstanding();\n+            return this._error;\n+        }\n+\n+        /**\n+         * epoch returns the current epoch of the cached query. The epoch is\n+         * incremented each time the cached result is refreshed; the first\n+         * result has an epoch of 1.\n+         */\n+        epoch():number {\n+            this.processOutstanding();\n+            return this._epoch;\n+        }\n+\n+        /** \n+         * This structure will be non-null when a query is in-flight, or has \n+         * completed but not been processed. When an in-flight query\n+         * completes, one and only one of these fields will contain a value.\n+         */\n+        private _outstanding:{\n+            result:promise<T>;\n+            error:property<Error>;\n+        }\n+\n+        /**\n+         * Check for a completed outstanding query, replacing cached results\n+         * with the result.\n+         */\n+        private processOutstanding() {","path":"resource/ui/ts/util/querycache.ts","position":116,"original_position":116,"commit_id":"a1e672cbbf64036f16aff51f318e7ff18baa52f4","original_commit_id":"a1e672cbbf64036f16aff51f318e7ff18baa52f4","user":{"login":"mrtracy","id":6969858,"avatar_url":"https://avatars.githubusercontent.com/u/6969858?v=3","gravatar_id":"","url":"https://api.github.com/users/mrtracy","html_url":"https://github.com/mrtracy","followers_url":"https://api.github.com/users/mrtracy/followers","following_url":"https://api.github.com/users/mrtracy/following{/other_user}","gists_url":"https://api.github.com/users/mrtracy/gists{/gist_id}","starred_url":"https://api.github.com/users/mrtracy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrtracy/subscriptions","organizations_url":"https://api.github.com/users/mrtracy/orgs","repos_url":"https://api.github.com/users/mrtracy/repos","events_url":"https://api.github.com/users/mrtracy/events{/privacy}","received_events_url":"https://api.github.com/users/mrtracy/received_events","type":"User","site_admin":false},"body":"I actually like mithril's promise model.  It depends on a redraw being triggered whenever a network call completes, but it means that very little code needs to be wrapped up in promises.\r\n\r\nIn this model, the only thing that promises should do is transform the result.","created_at":"2015-06-11T15:30:47Z","updated_at":"2015-06-11T15:30:47Z","html_url":"https://github.com/cockroachdb/cockroach/pull/1333#discussion_r32233277","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1333","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/32233277"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/1333#discussion_r32233277"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1333"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1333","id":37394341,"html_url":"https://github.com/cockroachdb/cockroach/pull/1333","diff_url":"https://github.com/cockroachdb/cockroach/pull/1333.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/1333.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/1333","number":1333,"state":"open","locked":false,"title":"Refactor Node/Store Admin Pages","user":{"login":"mrtracy","id":6969858,"avatar_url":"https://avatars.githubusercontent.com/u/6969858?v=3","gravatar_id":"","url":"https://api.github.com/users/mrtracy","html_url":"https://github.com/mrtracy","followers_url":"https://api.github.com/users/mrtracy/followers","following_url":"https://api.github.com/users/mrtracy/following{/other_user}","gists_url":"https://api.github.com/users/mrtracy/gists{/gist_id}","starred_url":"https://api.github.com/users/mrtracy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrtracy/subscriptions","organizations_url":"https://api.github.com/users/mrtracy/orgs","repos_url":"https://api.github.com/users/mrtracy/repos","events_url":"https://api.github.com/users/mrtracy/events{/privacy}","received_events_url":"https://api.github.com/users/mrtracy/received_events","type":"User","site_admin":false},"body":"Initial set of refactors for node/store status pages in the admin UI:\r\n+ Remove unused \"historical status\" functionality.\r\n+ Commonizes most of the data manipulation functions used by Store and Node\r\nmodels\r\n+ Moves Store and Node models to a shared Status file\r\n\r\nThere is still refactoring to be done after this change; for example, there is\r\nstill view code in the model.  However, this change is already becoming\r\nconsiderably complex.\r\n\r\nThis commit also fixes a bug in the Makefile where the Typescript was never\r\nrebuilt.","created_at":"2015-06-10T19:21:36Z","updated_at":"2015-06-11T15:30:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"25ed0c85650a02117c66192ba00c944f5a31a699","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1333/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1333/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/1333/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/a1e672cbbf64036f16aff51f318e7ff18baa52f4","head":{"label":"cockroachdb:mtracy/status_page_refactor","ref":"mtracy/status_page_refactor","sha":"a1e672cbbf64036f16aff51f318e7ff18baa52f4","user":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"repo":{"id":16563587,"name":"cockroach","full_name":"cockroachdb/cockroach","owner":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cockroachdb/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":false,"url":"https://api.github.com/repos/cockroachdb/cockroach","forks_url":"https://api.github.com/repos/cockroachdb/cockroach/forks","keys_url":"https://api.github.com/repos/cockroachdb/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cockroachdb/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cockroachdb/cockroach/teams","hooks_url":"https://api.github.com/repos/cockroachdb/cockroach/hooks","issue_events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/cockroachdb/cockroach/events","assignees_url":"https://api.github.com/repos/cockroachdb/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/cockroachdb/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/cockroachdb/cockroach/tags","blobs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cockroachdb/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/cockroachdb/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/cockroachdb/cockroach/languages","stargazers_url":"https://api.github.com/repos/cockroachdb/cockroach/stargazers","contributors_url":"https://api.github.com/repos/cockroachdb/cockroach/contributors","subscribers_url":"https://api.github.com/repos/cockroachdb/cockroach/subscribers","subscription_url":"https://api.github.com/repos/cockroachdb/cockroach/subscription","commits_url":"https://api.github.com/repos/cockroachdb/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/cockroachdb/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/cockroachdb/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/cockroachdb/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cockroachdb/cockroach/merges","archive_url":"https://api.github.com/repos/cockroachdb/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cockroachdb/cockroach/downloads","issues_url":"https://api.github.com/repos/cockroachdb/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/cockroachdb/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/cockroachdb/cockroach/releases{/id}","created_at":"2014-02-06T00:18:47Z","updated_at":"2015-06-11T14:58:22Z","pushed_at":"2015-06-11T15:27:56Z","git_url":"git://github.com/cockroachdb/cockroach.git","ssh_url":"git@github.com:cockroachdb/cockroach.git","clone_url":"https://github.com/cockroachdb/cockroach.git","svn_url":"https://github.com/cockroachdb/cockroach","homepage":null,"size":36166,"stargazers_count":4566,"watchers_count":4566,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":333,"mirror_url":null,"open_issues_count":88,"forks":333,"open_issues":88,"watchers":4566,"default_branch":"master"}},"base":{"label":"cockroachdb:master","ref":"master","sha":"982deebe56ae769c0047c6710057026bc1d4e270","user":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"repo":{"id":16563587,"name":"cockroach","full_name":"cockroachdb/cockroach","owner":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cockroachdb/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":false,"url":"https://api.github.com/repos/cockroachdb/cockroach","forks_url":"https://api.github.com/repos/cockroachdb/cockroach/forks","keys_url":"https://api.github.com/repos/cockroachdb/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cockroachdb/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cockroachdb/cockroach/teams","hooks_url":"https://api.github.com/repos/cockroachdb/cockroach/hooks","issue_events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/cockroachdb/cockroach/events","assignees_url":"https://api.github.com/repos/cockroachdb/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/cockroachdb/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/cockroachdb/cockroach/tags","blobs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cockroachdb/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/cockroachdb/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/cockroachdb/cockroach/languages","stargazers_url":"https://api.github.com/repos/cockroachdb/cockroach/stargazers","contributors_url":"https://api.github.com/repos/cockroachdb/cockroach/contributors","subscribers_url":"https://api.github.com/repos/cockroachdb/cockroach/subscribers","subscription_url":"https://api.github.com/repos/cockroachdb/cockroach/subscription","commits_url":"https://api.github.com/repos/cockroachdb/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/cockroachdb/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/cockroachdb/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/cockroachdb/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cockroachdb/cockroach/merges","archive_url":"https://api.github.com/repos/cockroachdb/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cockroachdb/cockroach/downloads","issues_url":"https://api.github.com/repos/cockroachdb/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/cockroachdb/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/cockroachdb/cockroach/releases{/id}","created_at":"2014-02-06T00:18:47Z","updated_at":"2015-06-11T14:58:22Z","pushed_at":"2015-06-11T15:27:56Z","git_url":"git://github.com/cockroachdb/cockroach.git","ssh_url":"git@github.com:cockroachdb/cockroach.git","clone_url":"https://github.com/cockroachdb/cockroach.git","svn_url":"https://github.com/cockroachdb/cockroach","homepage":null,"size":36166,"stargazers_count":4566,"watchers_count":4566,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":333,"mirror_url":null,"open_issues_count":88,"forks":333,"open_issues":88,"watchers":4566,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1333"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/1333"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/1333"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/1333/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1333/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1333/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/a1e672cbbf64036f16aff51f318e7ff18baa52f4"}}}}