payload: {"action":"created","comment":{"url":"https://api.github.com/repos/artefactual/atom/pulls/comments/330732763","pull_request_review_id":296476129,"id":330732763,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDMzMDczMjc2Mw==","diff_hunk":"@@ -612,32 +619,67 @@ public function getNameAccessPoints()\n   }\n \n   /*\n-   * Get related terms and its ancestors\n+   * Get related terms plus any ancestors\n    */\n   protected function getRelatedTerms($typeId)\n   {\n+    $relatedTerms = array();\n+\n     $sql  = 'SELECT\n-                DISTINCT term.id,\n-                term.taxonomy_id,\n-                term.source_culture,\n-                slug.slug,\n-                i18n.name';\n+                DISTINCT current.id';\n     $sql .= ' FROM '.QubitObjectTermRelation::TABLE_NAME.' otr';\n     $sql .= ' JOIN '.QubitTerm::TABLE_NAME.' current\n                 ON otr.term_id = current.id';\n-    $sql .= ' JOIN '.QubitTerm::TABLE_NAME.' term\n-                ON term.lft <= current.lft AND term.rgt >= current.rgt';\n-    $sql .= ' JOIN '.QubitTermI18n::TABLE_NAME.' i18n\n-                ON term.id = i18n.id';\n-    $sql .= ' JOIN '.QubitSlug::TABLE_NAME.' slug\n-                ON term.id = slug.object_id';\n-    $sql .= ' WHERE otr.object_id = ?\n-               AND term.taxonomy_id = ?';\n+    $sql .= ' WHERE otr.object_id = :id\n+                AND current.taxonomy_id = :taxonomyId';\n \n     self::$statements['relatedTerms'] = self::$conn->prepare($sql);\n-    self::$statements['relatedTerms']->execute(array($this->__get('id'), $typeId));\n+    self::$statements['relatedTerms']->execute(array(':id' => $this->__get('id'), ':taxonomyId' => $typeId));\n+\n+    // Get directly related terms.\n+    $rows = self::$statements['relatedTerms']->fetchAll(PDO::FETCH_ASSOC);\n+\n+    if (0 == count($rows))\n+    {\n+      return $relatedTerms;\n+    }\n+\n+    // Iterate over each directly related term, adding all ancestors of each\n+    foreach($rows as $row)\n+    {\n+      $relatedTerms = array_merge($relatedTerms, $this->recursivelyGetParentTerms($row['id']));\n+    }\n+\n+    $relatedTerms = array_unique($relatedTerms);\n+\n+    return $relatedTerms;\n+  }\n+\n+  /**\n+   * Recursively find all parent terms for any given term. Subject, Place and\n+   * Genre terms are preloaded in array $this->termParentList. The import array $ids is\n+   * appended to for every parent that is added on each recursive call.\n+   *\n+   * @param array $id  The term id to find the parents for.\n+   * @return array  Array with directly related term first, followed by\n+   *                any parents found, in child to top parent order.\n+   */\n+  private function recursivelyGetParentTerms($id)\n+  {\n+    if (null === $parent = $this->termParentList[$id])\n+    {\n+      return array($id);\n+    }\n \n-    return self::$statements['relatedTerms']->fetchAll(PDO::FETCH_OBJ);\n+    // Do not include root term id.\n+    if (QubitTerm::ROOT_ID == $parent)\n+    {\n+      return array($id);\n+    }\n+    else\n+    {\n+      return array_merge(array($id), $this->recursivelyGetParentTerms($parent));\n+    }","path":"plugins/arElasticSearchPlugin/lib/model/arElasticSearchInformationObjectPdo.class.php","position":101,"original_position":101,"commit_id":"4e70664e9566a5246836c8b7367ad81a4572cd44","original_commit_id":"4e70664e9566a5246836c8b7367ad81a4572cd44","user":{"login":"sbreker","id":3812460,"node_id":"MDQ6VXNlcjM4MTI0NjA=","avatar_url":"https://avatars2.githubusercontent.com/u/3812460?v=4","gravatar_id":"","url":"https://api.github.com/users/sbreker","html_url":"https://github.com/sbreker","followers_url":"https://api.github.com/users/sbreker/followers","following_url":"https://api.github.com/users/sbreker/following{/other_user}","gists_url":"https://api.github.com/users/sbreker/gists{/gist_id}","starred_url":"https://api.github.com/users/sbreker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbreker/subscriptions","organizations_url":"https://api.github.com/users/sbreker/orgs","repos_url":"https://api.github.com/users/sbreker/repos","events_url":"https://api.github.com/users/sbreker/events{/privacy}","received_events_url":"https://api.github.com/users/sbreker/received_events","type":"User","site_admin":false},"body":"Change made in next PR.","created_at":"2019-10-02T19:34:57Z","updated_at":"2019-10-02T19:34:58Z","html_url":"https://github.com/artefactual/atom/pull/974#discussion_r330732763","pull_request_url":"https://api.github.com/repos/artefactual/atom/pulls/974","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/artefactual/atom/pulls/comments/330732763"},"html":{"href":"https://github.com/artefactual/atom/pull/974#discussion_r330732763"},"pull_request":{"href":"https://api.github.com/repos/artefactual/atom/pulls/974"}},"in_reply_to_id":329591410},"pull_request":{"url":"https://api.github.com/repos/artefactual/atom/pulls/974","id":320507943,"node_id":"MDExOlB1bGxSZXF1ZXN0MzIwNTA3OTQz","html_url":"https://github.com/artefactual/atom/pull/974","diff_url":"https://github.com/artefactual/atom/pull/974.diff","patch_url":"https://github.com/artefactual/atom/pull/974.patch","issue_url":"https://api.github.com/repos/artefactual/atom/issues/974","number":974,"state":"open","locked":false,"title":"Related term ES index speed, refs #13175","user":{"login":"sbreker","id":3812460,"node_id":"MDQ6VXNlcjM4MTI0NjA=","avatar_url":"https://avatars2.githubusercontent.com/u/3812460?v=4","gravatar_id":"","url":"https://api.github.com/users/sbreker","html_url":"https://github.com/sbreker","followers_url":"https://api.github.com/users/sbreker/followers","following_url":"https://api.github.com/users/sbreker/following{/other_user}","gists_url":"https://api.github.com/users/sbreker/gists{/gist_id}","starred_url":"https://api.github.com/users/sbreker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbreker/subscriptions","organizations_url":"https://api.github.com/users/sbreker/orgs","repos_url":"https://api.github.com/users/sbreker/repos","events_url":"https://api.github.com/users/sbreker/events{/privacy}","received_events_url":"https://api.github.com/users/sbreker/received_events","type":"User","site_admin":false},"body":"This commit contains an enhancement to speed up ES indexing of\r\ninformation objects when there is a large number of terms in the terms\r\ntable.\r\n\r\nSubject, place and genre term ids and parent_ids are preloaded into an\r\narray so a term's parent can be found directly using the term id as the\r\narray index.\r\n\r\nFor each directly related term, parents are found by searching the term\r\narray recursively instead of using the nested set ancestors query using\r\nthe LFT and RGT columns.\r\n\r\nThis change results in a large performance increase when indexing\r\ninformation objects when testing with ~350K place and subject terms.","created_at":"2019-09-23T22:32:12Z","updated_at":"2019-10-02T19:34:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cd26764f79451177e721ae4ddc38e7f03b67c448","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/artefactual/atom/pulls/974/commits","review_comments_url":"https://api.github.com/repos/artefactual/atom/pulls/974/comments","review_comment_url":"https://api.github.com/repos/artefactual/atom/pulls/comments{/number}","comments_url":"https://api.github.com/repos/artefactual/atom/issues/974/comments","statuses_url":"https://api.github.com/repos/artefactual/atom/statuses/4e70664e9566a5246836c8b7367ad81a4572cd44","head":{"label":"artefactual:dev/issue-13175-related-terms-indexing-performance","ref":"dev/issue-13175-related-terms-indexing-performance","sha":"4e70664e9566a5246836c8b7367ad81a4572cd44","user":{"login":"artefactual","id":1163545,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNjM1NDU=","avatar_url":"https://avatars1.githubusercontent.com/u/1163545?v=4","gravatar_id":"","url":"https://api.github.com/users/artefactual","html_url":"https://github.com/artefactual","followers_url":"https://api.github.com/users/artefactual/followers","following_url":"https://api.github.com/users/artefactual/following{/other_user}","gists_url":"https://api.github.com/users/artefactual/gists{/gist_id}","starred_url":"https://api.github.com/users/artefactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artefactual/subscriptions","organizations_url":"https://api.github.com/users/artefactual/orgs","repos_url":"https://api.github.com/users/artefactual/repos","events_url":"https://api.github.com/users/artefactual/events{/privacy}","received_events_url":"https://api.github.com/users/artefactual/received_events","type":"Organization","site_admin":false},"repo":{"id":5705943,"node_id":"MDEwOlJlcG9zaXRvcnk1NzA1OTQz","name":"atom","full_name":"artefactual/atom","private":false,"owner":{"login":"artefactual","id":1163545,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNjM1NDU=","avatar_url":"https://avatars1.githubusercontent.com/u/1163545?v=4","gravatar_id":"","url":"https://api.github.com/users/artefactual","html_url":"https://github.com/artefactual","followers_url":"https://api.github.com/users/artefactual/followers","following_url":"https://api.github.com/users/artefactual/following{/other_user}","gists_url":"https://api.github.com/users/artefactual/gists{/gist_id}","starred_url":"https://api.github.com/users/artefactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artefactual/subscriptions","organizations_url":"https://api.github.com/users/artefactual/orgs","repos_url":"https://api.github.com/users/artefactual/repos","events_url":"https://api.github.com/users/artefactual/events{/privacy}","received_events_url":"https://api.github.com/users/artefactual/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/artefactual/atom","description":"Open-source, web application for archival description and public access.","fork":false,"url":"https://api.github.com/repos/artefactual/atom","forks_url":"https://api.github.com/repos/artefactual/atom/forks","keys_url":"https://api.github.com/repos/artefactual/atom/keys{/key_id}","collaborators_url":"https://api.github.com/repos/artefactual/atom/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/artefactual/atom/teams","hooks_url":"https://api.github.com/repos/artefactual/atom/hooks","issue_events_url":"https://api.github.com/repos/artefactual/atom/issues/events{/number}","events_url":"https://api.github.com/repos/artefactual/atom/events","assignees_url":"https://api.github.com/repos/artefactual/atom/assignees{/user}","branches_url":"https://api.github.com/repos/artefactual/atom/branches{/branch}","tags_url":"https://api.github.com/repos/artefactual/atom/tags","blobs_url":"https://api.github.com/repos/artefactual/atom/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/artefactual/atom/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/artefactual/atom/git/refs{/sha}","trees_url":"https://api.github.com/repos/artefactual/atom/git/trees{/sha}","statuses_url":"https://api.github.com/repos/artefactual/atom/statuses/{sha}","languages_url":"https://api.github.com/repos/artefactual/atom/languages","stargazers_url":"https://api.github.com/repos/artefactual/atom/stargazers","contributors_url":"https://api.github.com/repos/artefactual/atom/contributors","subscribers_url":"https://api.github.com/repos/artefactual/atom/subscribers","subscription_url":"https://api.github.com/repos/artefactual/atom/subscription","commits_url":"https://api.github.com/repos/artefactual/atom/commits{/sha}","git_commits_url":"https://api.github.com/repos/artefactual/atom/git/commits{/sha}","comments_url":"https://api.github.com/repos/artefactual/atom/comments{/number}","issue_comment_url":"https://api.github.com/repos/artefactual/atom/issues/comments{/number}","contents_url":"https://api.github.com/repos/artefactual/atom/contents/{+path}","compare_url":"https://api.github.com/repos/artefactual/atom/compare/{base}...{head}","merges_url":"https://api.github.com/repos/artefactual/atom/merges","archive_url":"https://api.github.com/repos/artefactual/atom/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/artefactual/atom/downloads","issues_url":"https://api.github.com/repos/artefactual/atom/issues{/number}","pulls_url":"https://api.github.com/repos/artefactual/atom/pulls{/number}","milestones_url":"https://api.github.com/repos/artefactual/atom/milestones{/number}","notifications_url":"https://api.github.com/repos/artefactual/atom/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/artefactual/atom/labels{/name}","releases_url":"https://api.github.com/repos/artefactual/atom/releases{/id}","deployments_url":"https://api.github.com/repos/artefactual/atom/deployments","created_at":"2012-09-06T17:35:28Z","updated_at":"2019-10-01T23:24:40Z","pushed_at":"2019-10-02T00:16:43Z","git_url":"git://github.com/artefactual/atom.git","ssh_url":"git@github.com:artefactual/atom.git","clone_url":"https://github.com/artefactual/atom.git","svn_url":"https://github.com/artefactual/atom","homepage":"http://www.accesstomemory.org","size":70723,"stargazers_count":113,"watchers_count":113,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":68,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":10,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":68,"open_issues":10,"watchers":113,"default_branch":"qa/2.6.x"}},"base":{"label":"artefactual:qa/2.6.x","ref":"qa/2.6.x","sha":"0814c0f7767cedbd2e644103f7ae189a9f98bb84","user":{"login":"artefactual","id":1163545,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNjM1NDU=","avatar_url":"https://avatars1.githubusercontent.com/u/1163545?v=4","gravatar_id":"","url":"https://api.github.com/users/artefactual","html_url":"https://github.com/artefactual","followers_url":"https://api.github.com/users/artefactual/followers","following_url":"https://api.github.com/users/artefactual/following{/other_user}","gists_url":"https://api.github.com/users/artefactual/gists{/gist_id}","starred_url":"https://api.github.com/users/artefactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artefactual/subscriptions","organizations_url":"https://api.github.com/users/artefactual/orgs","repos_url":"https://api.github.com/users/artefactual/repos","events_url":"https://api.github.com/users/artefactual/events{/privacy}","received_events_url":"https://api.github.com/users/artefactual/received_events","type":"Organization","site_admin":false},"repo":{"id":5705943,"node_id":"MDEwOlJlcG9zaXRvcnk1NzA1OTQz","name":"atom","full_name":"artefactual/atom","private":false,"owner":{"login":"artefactual","id":1163545,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNjM1NDU=","avatar_url":"https://avatars1.githubusercontent.com/u/1163545?v=4","gravatar_id":"","url":"https://api.github.com/users/artefactual","html_url":"https://github.com/artefactual","followers_url":"https://api.github.com/users/artefactual/followers","following_url":"https://api.github.com/users/artefactual/following{/other_user}","gists_url":"https://api.github.com/users/artefactual/gists{/gist_id}","starred_url":"https://api.github.com/users/artefactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artefactual/subscriptions","organizations_url":"https://api.github.com/users/artefactual/orgs","repos_url":"https://api.github.com/users/artefactual/repos","events_url":"https://api.github.com/users/artefactual/events{/privacy}","received_events_url":"https://api.github.com/users/artefactual/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/artefactual/atom","description":"Open-source, web application for archival description and public access.","fork":false,"url":"https://api.github.com/repos/artefactual/atom","forks_url":"https://api.github.com/repos/artefactual/atom/forks","keys_url":"https://api.github.com/repos/artefactual/atom/keys{/key_id}","collaborators_url":"https://api.github.com/repos/artefactual/atom/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/artefactual/atom/teams","hooks_url":"https://api.github.com/repos/artefactual/atom/hooks","issue_events_url":"https://api.github.com/repos/artefactual/atom/issues/events{/number}","events_url":"https://api.github.com/repos/artefactual/atom/events","assignees_url":"https://api.github.com/repos/artefactual/atom/assignees{/user}","branches_url":"https://api.github.com/repos/artefactual/atom/branches{/branch}","tags_url":"https://api.github.com/repos/artefactual/atom/tags","blobs_url":"https://api.github.com/repos/artefactual/atom/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/artefactual/atom/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/artefactual/atom/git/refs{/sha}","trees_url":"https://api.github.com/repos/artefactual/atom/git/trees{/sha}","statuses_url":"https://api.github.com/repos/artefactual/atom/statuses/{sha}","languages_url":"https://api.github.com/repos/artefactual/atom/languages","stargazers_url":"https://api.github.com/repos/artefactual/atom/stargazers","contributors_url":"https://api.github.com/repos/artefactual/atom/contributors","subscribers_url":"https://api.github.com/repos/artefactual/atom/subscribers","subscription_url":"https://api.github.com/repos/artefactual/atom/subscription","commits_url":"https://api.github.com/repos/artefactual/atom/commits{/sha}","git_commits_url":"https://api.github.com/repos/artefactual/atom/git/commits{/sha}","comments_url":"https://api.github.com/repos/artefactual/atom/comments{/number}","issue_comment_url":"https://api.github.com/repos/artefactual/atom/issues/comments{/number}","contents_url":"https://api.github.com/repos/artefactual/atom/contents/{+path}","compare_url":"https://api.github.com/repos/artefactual/atom/compare/{base}...{head}","merges_url":"https://api.github.com/repos/artefactual/atom/merges","archive_url":"https://api.github.com/repos/artefactual/atom/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/artefactual/atom/downloads","issues_url":"https://api.github.com/repos/artefactual/atom/issues{/number}","pulls_url":"https://api.github.com/repos/artefactual/atom/pulls{/number}","milestones_url":"https://api.github.com/repos/artefactual/atom/milestones{/number}","notifications_url":"https://api.github.com/repos/artefactual/atom/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/artefactual/atom/labels{/name}","releases_url":"https://api.github.com/repos/artefactual/atom/releases{/id}","deployments_url":"https://api.github.com/repos/artefactual/atom/deployments","created_at":"2012-09-06T17:35:28Z","updated_at":"2019-10-01T23:24:40Z","pushed_at":"2019-10-02T00:16:43Z","git_url":"git://github.com/artefactual/atom.git","ssh_url":"git@github.com:artefactual/atom.git","clone_url":"https://github.com/artefactual/atom.git","svn_url":"https://github.com/artefactual/atom","homepage":"http://www.accesstomemory.org","size":70723,"stargazers_count":113,"watchers_count":113,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":68,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":10,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":68,"open_issues":10,"watchers":113,"default_branch":"qa/2.6.x"}},"_links":{"self":{"href":"https://api.github.com/repos/artefactual/atom/pulls/974"},"html":{"href":"https://github.com/artefactual/atom/pull/974"},"issue":{"href":"https://api.github.com/repos/artefactual/atom/issues/974"},"comments":{"href":"https://api.github.com/repos/artefactual/atom/issues/974/comments"},"review_comments":{"href":"https://api.github.com/repos/artefactual/atom/pulls/974/comments"},"review_comment":{"href":"https://api.github.com/repos/artefactual/atom/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/artefactual/atom/pulls/974/commits"},"statuses":{"href":"https://api.github.com/repos/artefactual/atom/statuses/4e70664e9566a5246836c8b7367ad81a4572cd44"}},"author_association":"CONTRIBUTOR"}}
other: {"actor":{"display_login":"sbreker"}}