Skip to content

Commit

Permalink
Merge branch 'develop' into fix-general-settings-access-denied-for-ma…
Browse files Browse the repository at this point in the history
…nage-settings-permission
  • Loading branch information
rowasc authored Mar 16, 2020
2 parents 88124f3 + b8e701d commit 54358be
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/App/Repository/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,31 @@ protected function selectQuery(array $where = [])
$query = parent::selectQuery($where);

// Join to messages and load message id
$query->join('messages', 'LEFT')->on('posts.id', '=', 'messages.post_id')
$query
->join('messages', 'LEFT')
->on('posts.id', '=', 'messages.post_id')
->select(
['messages.id', 'message_id'],
['messages.type', 'source'],
['messages.contact_id', 'contact_id'],
['messages.data_source_message_id', 'data_source_message_id']
['messages.type', 'source']
);

/*
* The above join is optimized by the (post_id,type) index on messages.
*
* Add now a separate join into same table, to retrieve more message details.
*
* Compared to having all the details come from a single join, this will speed
* things up *very* considerably, *IF* there are many messages, *BUT* rather
* few matches of posts to messages.
* (This easily happens when twitter searches have few usable results,
* spam filled e-mail inboxes are being imported, etc)
*/
$query
->join(['messages', 'msgs2'], 'LEFT')
->on('msgs2.id', '=', 'messages.id')
->select(
['msgs2.contact_id', 'contact_id'],
['msgs2.data_source_message_id', 'data_source_message_id']
);

// Join to form
Expand Down

0 comments on commit 54358be

Please sign in to comment.