Skip to content

Commit 1e03857

Browse files
committed
* fix regression of not querying forum moderator of thread latest repliers that introduced in de936c0 @ App\Controller\PostsController::query()
@ be
1 parent de936c0 commit 1e03857

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

be/src/Controller/PostsController.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ public function query(Request $request): array
6363
$this->stopwatch->stop('fillWithParentPost');
6464

6565
$this->stopwatch->start('queryUsers');
66-
$latestRepliers = $this->latestReplierRepository->getLatestRepliersWithoutNameWhenHasUid(
67-
$this->query->postsTree->threads->map(fn(Thread $thread) => $thread->getLatestReplierId()),
68-
);
66+
$latestRepliersIdKeyByFid = $this->query->postsTree->threads
67+
->map(fn(Thread $thread) => ['fid' => $thread->getFid(), 'latestReplierId' => $thread->getLatestReplierId()])
68+
->groupBy(fn(array $fidAndLatestReplierId) => $fidAndLatestReplierId['fid'])
69+
->map(fn(Collection $fidAndLatestRepliersUid) => $fidAndLatestRepliersUid->pluck('latestReplierId'));
70+
$latestRepliers = $this->latestReplierRepository->getLatestRepliersWithoutNameWhenHasUid($latestRepliersIdKeyByFid->flatten());
6971
$posts = collect([
7072
$this->query->postsTree->threads,
7173
$this->query->postsTree->replies,
@@ -92,9 +94,22 @@ public function query(Request $request): array
9294
->map(fn(Collection $fidAndAuthorsUid) => $fidAndAuthorsUid->pluck('authorUid'));
9395
$authorExpGrades = collect($this->authorExpGradeRepository->getLatestOfUsers($authorsUidKeyByFid))
9496
->keyBy(fn(AuthorExpGrade $authorExpGrade) => $authorExpGrade->uid);
95-
$forumModerators = collect($this->forumModeratorRepository->getLatestOfUsers($authorsUidKeyByFid
96-
->map(fn(Collection $authorsUid) => $authorsUid
97-
->map(fn(int $authorUid) => $users->get($authorUid)?->getPortrait())
97+
98+
/** @var Collection<int, int> $intersectedFidInUsersId */
99+
/** @var Collection<int, int> $uniqueFidInAuthorsUid */
100+
[$intersectedFidInUsersId, $uniqueFidInAuthorsUid] = $authorsUidKeyByFid->keys()
101+
->partition(fn(int $fid) => $latestRepliersIdKeyByFid->keys()->contains($fid));
102+
$usersIdKeyByFid = $intersectedFidInUsersId
103+
->mapWithKeys(fn(int $fid) => [$fid =>
104+
$latestRepliersIdKeyByFid[$fid]
105+
->map(fn(int $latestReplierId) => $latestRepliersUidKeyById->get($latestReplierId))
106+
->filter(fn(?int $latestReplierUid) => $latestReplierUid !== null)
107+
->merge($authorsUidKeyByFid[$fid])
108+
->unique()])
109+
->merge($authorsUidKeyByFid->only($uniqueFidInAuthorsUid));
110+
$forumModerators = collect($this->forumModeratorRepository->getLatestOfUsers($usersIdKeyByFid
111+
->map(fn(Collection $usersId) => $usersId
112+
->map(fn(int $uid) => $users->get($uid)?->getPortrait())
98113
->filter(fn(?string $portrait) => $portrait !== null))
99114
))->keyBy(fn(ForumModerator $forumModerator) => $forumModerator->portrait);
100115
$users = $users->each(fn(User $user) => $user->setForumSpecific([

0 commit comments

Comments
 (0)