{"action":"created","comment":{"url":"https://api.github.com/repos/angular/angular/pulls/comments/38683006","id":38683006,"diff_hunk":"@@ -1124,37 +933,79 @@ export class QueryError extends BaseException {\n \n export class QueryRef {\n   constructor(public query: QueryMetadata, public list: QueryList<any>,\n-              public originator: ElementInjector) {}\n+              public originator: ElementInjector,\n+              public dirty: boolean = true) {}\n \n   get isViewQuery(): boolean { return this.query.isViewQuery; }\n \n   update(): void {\n+    if (!this.dirty) return;\n+    this._update();\n+    this.dirty = false;\n+  }\n+\n+  private _update(): void {\n     var aggregator = [];\n     if (this.query.isViewQuery) {\n+      var view = this.originator.view;\n       // intentionally skipping originator for view queries.\n-      var rootViewInjectors = this.originator.getRootViewInjectors();\n-      for (var i = 0; i < rootViewInjectors.length; i++) {\n-        this.visit(rootViewInjectors[i], aggregator);\n-      }\n+      var nestedView = view.getNestedView(\n+          view.elementOffset + this.originator.getBoundElementIndex());\n+      if (isPresent(nestedView)) this.visitView(nestedView, aggregator);\n     } else {\n       this.visit(this.originator, aggregator);\n     }\n     this.list.reset(aggregator);\n-  }\n+  };\n \n   visit(inj: ElementInjector, aggregator: any[]): void {\n-    if (isBlank(inj) || !inj._hasQuery(this) || !inj.hydrated) return;\n+    if (isBlank(inj) || !inj.hydrated) return;\n+\n+    var view = inj.view;\n+    var startIdx = ListWrapper.indexOf(view.elementInjectors, inj);\n+    for (var i = startIdx; i < view.elementOffset + view.ownBindersCount; i++) {\n+      var curInj = view.elementInjectors[i];\n+      if (isBlank(curInj)) continue;\n+      // The first injector after inj, that is outside the subtree rooted at\n+      // inj has to have a null parent or a parent that is an ancestor of inj.\n+      if (i > startIdx && (isBlank(curInj) ||\n+                           ListWrapper.indexOf(view.elementInjectors, curInj.parent) < startIdx)) {\n+        break;\n+      }\n+\n+      if (!this.query.descendants &&\n+          !(curInj.parent == this.originator || curInj == this.originator))\n+        continue;\n+\n+      this.visitInjector(curInj, aggregator);","path":"modules/angular2/src/core/compiler/element_injector.ts","position":444,"original_position":444,"commit_id":"269da457922b3ece26062a4da697d1664c35c033","original_commit_id":"269da457922b3ece26062a4da697d1664c35c033","user":{"login":"rkirov","id":95713,"avatar_url":"https://avatars.githubusercontent.com/u/95713?v=3","gravatar_id":"","url":"https://api.github.com/users/rkirov","html_url":"https://github.com/rkirov","followers_url":"https://api.github.com/users/rkirov/followers","following_url":"https://api.github.com/users/rkirov/following{/other_user}","gists_url":"https://api.github.com/users/rkirov/gists{/gist_id}","starred_url":"https://api.github.com/users/rkirov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkirov/subscriptions","organizations_url":"https://api.github.com/users/rkirov/orgs","repos_url":"https://api.github.com/users/rkirov/repos","events_url":"https://api.github.com/users/rkirov/events{/privacy}","received_events_url":"https://api.github.com/users/rkirov/received_events","type":"User","site_admin":false},"body":"we visit view containers before any children of inj. Theoretically this can be a problem for a very special imperative view container.","created_at":"2015-09-03T18:56:28Z","updated_at":"2015-09-03T18:56:28Z","html_url":"https://github.com/angular/angular/pull/3973#discussion_r38683006","pull_request_url":"https://api.github.com/repos/angular/angular/pulls/3973","_links":{"self":{"href":"https://api.github.com/repos/angular/angular/pulls/comments/38683006"},"html":{"href":"https://github.com/angular/angular/pull/3973#discussion_r38683006"},"pull_request":{"href":"https://api.github.com/repos/angular/angular/pulls/3973"}}},"pull_request":{"url":"https://api.github.com/repos/angular/angular/pulls/3973","id":44066801,"html_url":"https://github.com/angular/angular/pull/3973","diff_url":"https://github.com/angular/angular/pull/3973.diff","patch_url":"https://github.com/angular/angular/pull/3973.patch","issue_url":"https://api.github.com/repos/angular/angular/issues/3973","number":3973,"state":"open","locked":false,"title":"feat(query): implement query update mechanism based on views.","user":{"login":"rkirov","id":95713,"avatar_url":"https://avatars.githubusercontent.com/u/95713?v=3","gravatar_id":"","url":"https://api.github.com/users/rkirov","html_url":"https://github.com/rkirov","followers_url":"https://api.github.com/users/rkirov/followers","following_url":"https://api.github.com/users/rkirov/following{/other_user}","gists_url":"https://api.github.com/users/rkirov/gists{/gist_id}","starred_url":"https://api.github.com/users/rkirov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkirov/subscriptions","organizations_url":"https://api.github.com/users/rkirov/orgs","repos_url":"https://api.github.com/users/rkirov/repos","events_url":"https://api.github.com/users/rkirov/events{/privacy}","received_events_url":"https://api.github.com/users/rkirov/received_events","type":"User","site_admin":false},"body":"Instead of working with finer grained element injectors, queries now\r\niterate through the views as static units of modification of the\r\napplication structure. Views already contain element injectors in the\r\ncorrect depth-first preorder.\r\n\r\nThis allows us to remove children linked lists on element injectors and a\r\nlot of book keeping that is already present at the view level.\r\n\r\nQueries are recalculated using the afterContentChecked and\r\nafterViewChecked hooks, only during init and after a view container has\r\nchanged.\r\n\r\nBREAKING CHANGE:\r\nViewQuery no longer supports the descendants flag. It queries the whole\r\ncomponent view by default.","created_at":"2015-09-03T03:44:11Z","updated_at":"2015-09-03T18:56:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"18ee655faf19463859b5f32a74bb5da8492f0cce","assignee":{"login":"vsavkin","id":35996,"avatar_url":"https://avatars.githubusercontent.com/u/35996?v=3","gravatar_id":"","url":"https://api.github.com/users/vsavkin","html_url":"https://github.com/vsavkin","followers_url":"https://api.github.com/users/vsavkin/followers","following_url":"https://api.github.com/users/vsavkin/following{/other_user}","gists_url":"https://api.github.com/users/vsavkin/gists{/gist_id}","starred_url":"https://api.github.com/users/vsavkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsavkin/subscriptions","organizations_url":"https://api.github.com/users/vsavkin/orgs","repos_url":"https://api.github.com/users/vsavkin/repos","events_url":"https://api.github.com/users/vsavkin/events{/privacy}","received_events_url":"https://api.github.com/users/vsavkin/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/angular/angular/pulls/3973/commits","review_comments_url":"https://api.github.com/repos/angular/angular/pulls/3973/comments","review_comment_url":"https://api.github.com/repos/angular/angular/pulls/comments{/number}","comments_url":"https://api.github.com/repos/angular/angular/issues/3973/comments","statuses_url":"https://api.github.com/repos/angular/angular/statuses/269da457922b3ece26062a4da697d1664c35c033","head":{"label":"rkirov:query_by_view","ref":"query_by_view","sha":"269da457922b3ece26062a4da697d1664c35c033","user":{"login":"rkirov","id":95713,"avatar_url":"https://avatars.githubusercontent.com/u/95713?v=3","gravatar_id":"","url":"https://api.github.com/users/rkirov","html_url":"https://github.com/rkirov","followers_url":"https://api.github.com/users/rkirov/followers","following_url":"https://api.github.com/users/rkirov/following{/other_user}","gists_url":"https://api.github.com/users/rkirov/gists{/gist_id}","starred_url":"https://api.github.com/users/rkirov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkirov/subscriptions","organizations_url":"https://api.github.com/users/rkirov/orgs","repos_url":"https://api.github.com/users/rkirov/repos","events_url":"https://api.github.com/users/rkirov/events{/privacy}","received_events_url":"https://api.github.com/users/rkirov/received_events","type":"User","site_admin":false},"repo":{"id":25182881,"name":"angular","full_name":"rkirov/angular","owner":{"login":"rkirov","id":95713,"avatar_url":"https://avatars.githubusercontent.com/u/95713?v=3","gravatar_id":"","url":"https://api.github.com/users/rkirov","html_url":"https://github.com/rkirov","followers_url":"https://api.github.com/users/rkirov/followers","following_url":"https://api.github.com/users/rkirov/following{/other_user}","gists_url":"https://api.github.com/users/rkirov/gists{/gist_id}","starred_url":"https://api.github.com/users/rkirov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkirov/subscriptions","organizations_url":"https://api.github.com/users/rkirov/orgs","repos_url":"https://api.github.com/users/rkirov/repos","events_url":"https://api.github.com/users/rkirov/events{/privacy}","received_events_url":"https://api.github.com/users/rkirov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rkirov/angular","description":"","fork":true,"url":"https://api.github.com/repos/rkirov/angular","forks_url":"https://api.github.com/repos/rkirov/angular/forks","keys_url":"https://api.github.com/repos/rkirov/angular/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rkirov/angular/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rkirov/angular/teams","hooks_url":"https://api.github.com/repos/rkirov/angular/hooks","issue_events_url":"https://api.github.com/repos/rkirov/angular/issues/events{/number}","events_url":"https://api.github.com/repos/rkirov/angular/events","assignees_url":"https://api.github.com/repos/rkirov/angular/assignees{/user}","branches_url":"https://api.github.com/repos/rkirov/angular/branches{/branch}","tags_url":"https://api.github.com/repos/rkirov/angular/tags","blobs_url":"https://api.github.com/repos/rkirov/angular/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rkirov/angular/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rkirov/angular/git/refs{/sha}","trees_url":"https://api.github.com/repos/rkirov/angular/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rkirov/angular/statuses/{sha}","languages_url":"https://api.github.com/repos/rkirov/angular/languages","stargazers_url":"https://api.github.com/repos/rkirov/angular/stargazers","contributors_url":"https://api.github.com/repos/rkirov/angular/contributors","subscribers_url":"https://api.github.com/repos/rkirov/angular/subscribers","subscription_url":"https://api.github.com/repos/rkirov/angular/subscription","commits_url":"https://api.github.com/repos/rkirov/angular/commits{/sha}","git_commits_url":"https://api.github.com/repos/rkirov/angular/git/commits{/sha}","comments_url":"https://api.github.com/repos/rkirov/angular/comments{/number}","issue_comment_url":"https://api.github.com/repos/rkirov/angular/issues/comments{/number}","contents_url":"https://api.github.com/repos/rkirov/angular/contents/{+path}","compare_url":"https://api.github.com/repos/rkirov/angular/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rkirov/angular/merges","archive_url":"https://api.github.com/repos/rkirov/angular/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rkirov/angular/downloads","issues_url":"https://api.github.com/repos/rkirov/angular/issues{/number}","pulls_url":"https://api.github.com/repos/rkirov/angular/pulls{/number}","milestones_url":"https://api.github.com/repos/rkirov/angular/milestones{/number}","notifications_url":"https://api.github.com/repos/rkirov/angular/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rkirov/angular/labels{/name}","releases_url":"https://api.github.com/repos/rkirov/angular/releases{/id}","created_at":"2014-10-13T23:57:21Z","updated_at":"2015-09-01T22:31:04Z","pushed_at":"2015-09-03T04:44:57Z","git_url":"git://github.com/rkirov/angular.git","ssh_url":"git@github.com:rkirov/angular.git","clone_url":"https://github.com/rkirov/angular.git","svn_url":"https://github.com/rkirov/angular","homepage":null,"size":14310,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"angular:master","ref":"master","sha":"2fea0c26020444e4f1ab607f85f6a68a50dce0e4","user":{"login":"angular","id":139426,"avatar_url":"https://avatars.githubusercontent.com/u/139426?v=3","gravatar_id":"","url":"https://api.github.com/users/angular","html_url":"https://github.com/angular","followers_url":"https://api.github.com/users/angular/followers","following_url":"https://api.github.com/users/angular/following{/other_user}","gists_url":"https://api.github.com/users/angular/gists{/gist_id}","starred_url":"https://api.github.com/users/angular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/angular/subscriptions","organizations_url":"https://api.github.com/users/angular/orgs","repos_url":"https://api.github.com/users/angular/repos","events_url":"https://api.github.com/users/angular/events{/privacy}","received_events_url":"https://api.github.com/users/angular/received_events","type":"Organization","site_admin":false},"repo":{"id":24195339,"name":"angular","full_name":"angular/angular","owner":{"login":"angular","id":139426,"avatar_url":"https://avatars.githubusercontent.com/u/139426?v=3","gravatar_id":"","url":"https://api.github.com/users/angular","html_url":"https://github.com/angular","followers_url":"https://api.github.com/users/angular/followers","following_url":"https://api.github.com/users/angular/following{/other_user}","gists_url":"https://api.github.com/users/angular/gists{/gist_id}","starred_url":"https://api.github.com/users/angular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/angular/subscriptions","organizations_url":"https://api.github.com/users/angular/orgs","repos_url":"https://api.github.com/users/angular/repos","events_url":"https://api.github.com/users/angular/events{/privacy}","received_events_url":"https://api.github.com/users/angular/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/angular/angular","description":"","fork":false,"url":"https://api.github.com/repos/angular/angular","forks_url":"https://api.github.com/repos/angular/angular/forks","keys_url":"https://api.github.com/repos/angular/angular/keys{/key_id}","collaborators_url":"https://api.github.com/repos/angular/angular/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/angular/angular/teams","hooks_url":"https://api.github.com/repos/angular/angular/hooks","issue_events_url":"https://api.github.com/repos/angular/angular/issues/events{/number}","events_url":"https://api.github.com/repos/angular/angular/events","assignees_url":"https://api.github.com/repos/angular/angular/assignees{/user}","branches_url":"https://api.github.com/repos/angular/angular/branches{/branch}","tags_url":"https://api.github.com/repos/angular/angular/tags","blobs_url":"https://api.github.com/repos/angular/angular/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/angular/angular/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/angular/angular/git/refs{/sha}","trees_url":"https://api.github.com/repos/angular/angular/git/trees{/sha}","statuses_url":"https://api.github.com/repos/angular/angular/statuses/{sha}","languages_url":"https://api.github.com/repos/angular/angular/languages","stargazers_url":"https://api.github.com/repos/angular/angular/stargazers","contributors_url":"https://api.github.com/repos/angular/angular/contributors","subscribers_url":"https://api.github.com/repos/angular/angular/subscribers","subscription_url":"https://api.github.com/repos/angular/angular/subscription","commits_url":"https://api.github.com/repos/angular/angular/commits{/sha}","git_commits_url":"https://api.github.com/repos/angular/angular/git/commits{/sha}","comments_url":"https://api.github.com/repos/angular/angular/comments{/number}","issue_comment_url":"https://api.github.com/repos/angular/angular/issues/comments{/number}","contents_url":"https://api.github.com/repos/angular/angular/contents/{+path}","compare_url":"https://api.github.com/repos/angular/angular/compare/{base}...{head}","merges_url":"https://api.github.com/repos/angular/angular/merges","archive_url":"https://api.github.com/repos/angular/angular/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/angular/angular/downloads","issues_url":"https://api.github.com/repos/angular/angular/issues{/number}","pulls_url":"https://api.github.com/repos/angular/angular/pulls{/number}","milestones_url":"https://api.github.com/repos/angular/angular/milestones{/number}","notifications_url":"https://api.github.com/repos/angular/angular/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/angular/angular/labels{/name}","releases_url":"https://api.github.com/repos/angular/angular/releases{/id}","created_at":"2014-09-18T16:12:01Z","updated_at":"2015-09-03T18:39:45Z","pushed_at":"2015-09-03T18:51:05Z","git_url":"git://github.com/angular/angular.git","ssh_url":"git@github.com:angular/angular.git","clone_url":"https://github.com/angular/angular.git","svn_url":"https://github.com/angular/angular","homepage":"https://angular.io","size":49687,"stargazers_count":5127,"watchers_count":5127,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1367,"mirror_url":null,"open_issues_count":421,"forks":1367,"open_issues":421,"watchers":5127,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/angular/angular/pulls/3973"},"html":{"href":"https://github.com/angular/angular/pull/3973"},"issue":{"href":"https://api.github.com/repos/angular/angular/issues/3973"},"comments":{"href":"https://api.github.com/repos/angular/angular/issues/3973/comments"},"review_comments":{"href":"https://api.github.com/repos/angular/angular/pulls/3973/comments"},"review_comment":{"href":"https://api.github.com/repos/angular/angular/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/angular/angular/pulls/3973/commits"},"statuses":{"href":"https://api.github.com/repos/angular/angular/statuses/269da457922b3ece26062a4da697d1664c35c033"}}}}