Skip to content

Commit 020d40f

Browse files
committed
* remove param $fid @ App\Repository\Post\PostRepository::getPosts(), all its derived classes & its usages in App\PostsQuery\PostsTree::fillWithParentPost()
@ be
1 parent da6ecda commit 020d40f

6 files changed

Lines changed: 13 additions & 18 deletions

File tree

be/src/PostsQuery/PostsTree.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function fillWithParentPost(QueryResult $result): array
6060
->map(fn(ReplyKey $postKey) => $postKey->parentPostId)
6161
->concat($result->subReplies->map(fn(SubReplyKey $postKey) => $postKey->tid))
6262
->unique();
63-
$this->threads = collect($postModels['thread']->getPosts($fid, $parentThreadsID->concat($tids)))
63+
$this->threads = collect($postModels['thread']->getPosts($parentThreadsID->concat($tids)))
6464
->map(fn(\App\Entity\Post\Thread $entity) => Thread::fromEntity($entity))
6565
->each(static fn(Thread $thread) =>
6666
$thread->setIsMatchQuery($tids->contains($thread->getTid())));
@@ -70,14 +70,14 @@ public function fillWithParentPost(QueryResult $result): array
7070
/** @var Collection<int, int> $parentRepliesID parent pid of all sub replies */
7171
$parentRepliesID = $result->subReplies->map(fn(SubReplyKey $postKey) => $postKey->parentPostId)->unique();
7272
$allRepliesId = $parentRepliesID->concat($pids);
73-
$this->replies = collect($postModels['reply']->getPosts($fid, $allRepliesId))
73+
$this->replies = collect($postModels['reply']->getPosts($allRepliesId))
7474
->map(fn(\App\Entity\Post\Reply $entity) => Reply::fromEntity($entity))
7575
->each(static fn(Reply $reply) =>
7676
$reply->setIsMatchQuery($pids->contains($reply->getPid())));
7777
$this->stopwatch->stop('fillWithRepliesFields');
7878

7979
$this->stopwatch->start('fillWithSubRepliesFields');
80-
$this->subReplies = collect($postModels['subReply']->getPosts($fid, $spids))
80+
$this->subReplies = collect($postModels['subReply']->getPosts($spids))
8181
->map(fn(\App\Entity\Post\SubReply $entity) => SubReply::fromEntity($entity));
8282
$this->stopwatch->stop('fillWithSubRepliesFields');
8383

be/src/PostsQuery/QueryResult.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
/** @psalm-import-type PostsKeyByTypePluralName from CursorCodec */
2424
readonly class QueryResult
2525
{
26-
public int $fid;
27-
2826
/** @var Collection<int, ThreadKey> */
2927
public Collection $threads;
3028

@@ -125,9 +123,6 @@ public function setResult(
125123
$this->threads = $postsKeyByTypePluralName->get('threads', collect());
126124
$this->replies = $postsKeyByTypePluralName->get('replies', collect());
127125
$this->subReplies = $postsKeyByTypePluralName->get('subReplies', collect());
128-
$this->fid = $this->threads->first()->fid
129-
?? $this->replies->first()->fid
130-
?? $this->subReplies->first()->fid;
131126
$this->currentCursor = $cursorParamValue ?? '';
132127
$this->nextCursor = $hasMorePages
133128
? $this->cursorCodec->encodeNextCursor($postsKeyByTypePluralName->except(

be/src/Repository/Post/PostRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ abstract class PostRepository extends BaseRepository
1414
{
1515
abstract public function selectUnionPostKey(): QueryBuilder;
1616

17-
abstract public function getPosts(int $fid, array|\ArrayAccess $postsId): array;
17+
abstract public function getPosts(array|\ArrayAccess $postsId): array;
1818
}

be/src/Repository/Post/ReplyRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public function selectUnionPostKey(): QueryBuilder
2020
->select("'reply' AS postType", 't.pid AS postId', 't.fid', 't.tid', 't.pid');
2121
}
2222

23-
public function getPosts(int $fid, array|\ArrayAccess $postsId): array
23+
public function getPosts(array|\ArrayAccess $postsId): array
2424
{
25-
$dql = 'SELECT t FROM App\Entity\Post\Reply t WHERE t.fid = :fid AND t.pid IN (:pid)';
26-
return $this->getQueryResultWithParams($dql, ['fid' => $fid, 'pid' => $postsId]);
25+
$dql = 'SELECT t FROM App\Entity\Post\Reply t WHERE t.pid IN (:pid)';
26+
return $this->getQueryResultWithParams($dql, ['pid' => $postsId]);
2727
}
2828
}

be/src/Repository/Post/SubReplyRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public function selectUnionPostKey(): QueryBuilder
2020
->select("'subReply' AS postType", 't.spid AS postId', 't.fid', 't.tid', 't.pid');
2121
}
2222

23-
public function getPosts(int $fid, array|\ArrayAccess $postsId): array
23+
public function getPosts(array|\ArrayAccess $postsId): array
2424
{
25-
$dql = 'SELECT t FROM App\Entity\Post\SubReply t WHERE t.fid = :fid AND t.spid IN (:spid)';
26-
return $this->getQueryResultWithParams($dql, ['fid' => $fid, 'spid' => $postsId]);
25+
$dql = 'SELECT t FROM App\Entity\Post\SubReply t WHERE t.spid IN (:spid)';
26+
return $this->getQueryResultWithParams($dql, ['spid' => $postsId]);
2727
}
2828
}

be/src/Repository/Post/ThreadRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public function selectUnionPostKey(): QueryBuilder
2222
->select("'thread' AS postType", 't.tid AS postId', 't.fid', 't.tid', '0 AS pid');
2323
}
2424

25-
public function getPosts(int $fid, array|\ArrayAccess $postsId): array
25+
public function getPosts(array|\ArrayAccess $postsId): array
2626
{
27-
$dql = 'SELECT t FROM App\Entity\Post\Thread t WHERE t.fid = :fid AND t.tid IN (:tid)';
28-
return $this->getQueryResultWithParams($dql, ['fid' => $fid, 'tid' => $postsId]);
27+
$dql = 'SELECT t FROM App\Entity\Post\Thread t WHERE t.tid IN (:tid)';
28+
return $this->getQueryResultWithParams($dql, ['tid' => $postsId]);
2929
}
3030

3131
public function getThreadsIdByChunks(int $chunkSize): array

0 commit comments

Comments
 (0)