mirror of
https://github.com/flarum/framework.git
synced 2025-01-30 22:38:43 +08:00
Eagerload some needed relations in ListDiscussionsController (#2639)
This commit is contained in:
parent
970db778cd
commit
eb6744f5fd
|
@ -110,9 +110,20 @@ class ListDiscussionsController extends AbstractListController
|
|||
|
||||
Discussion::setStateUser($actor);
|
||||
|
||||
// Eager load groups for use in the policies (isAdmin check)
|
||||
if (in_array('mostRelevantPost.user', $include)) {
|
||||
$include[] = 'mostRelevantPost.user.groups';
|
||||
|
||||
// If the first level of the relationship wasn't explicitly included,
|
||||
// add it so the code below can look for it
|
||||
if (! in_array('mostRelevantPost', $include)) {
|
||||
$include[] = 'mostRelevantPost';
|
||||
}
|
||||
}
|
||||
|
||||
$results = $results->getResults()->load($include);
|
||||
|
||||
if ($relations = array_intersect($include, ['firstPost', 'lastPost'])) {
|
||||
if ($relations = array_intersect($include, ['firstPost', 'lastPost', 'mostRelevantPost'])) {
|
||||
foreach ($results as $discussion) {
|
||||
foreach ($relations as $relation) {
|
||||
if ($discussion->$relation) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user