Skip to content

Commit

Permalink
speed up very slow topic query
Browse files Browse the repository at this point in the history
It turns out that doing a SELECT foo FROM bar WHERE id in (SELECT)
fetches all the records in bar which is very slow for the epobjects
table so do a much quicker join.
  • Loading branch information
struan committed May 15, 2017
1 parent 45b0aad commit a647a31
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions classes/Topic.php
Expand Up @@ -115,10 +115,10 @@ function onFrontPage() {

private function _getContentIDs() {
$q = $this->db->query(
"SELECT body, gid, ep.epobject_id FROM epobject ep JOIN hansard h on ep.epobject_id = h.epobject_id
WHERE ep.epobject_id in (
SELECT epobject_id from topic_epobjects WHERE topic_key = :topic_key
)",
"SELECT body, gid, ep.epobject_id FROM epobject ep
JOIN hansard h on ep.epobject_id = h.epobject_id
JOIN topic_epobjects te on te.epobject_id = ep.epobject_id
WHERE topic_key = :topic_key",
array(
':topic_key' => $this->id
)
Expand Down

0 comments on commit a647a31

Please sign in to comment.