Skip to content

Commit

Permalink
* replace all private prop and their getter in readonly DTO classes w…
Browse files Browse the repository at this point in the history
…ith public prop @ `App\DTO`

- stopwatch with label `initPaginators` as its duration is transient @ `App\PostsQuery\BaseQuery->setResult()`
@ be
  • Loading branch information
n0099 committed Oct 12, 2024
1 parent 24c92db commit e9b73bb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 44 deletions.
4 changes: 2 additions & 2 deletions be/src/Controller/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ public function query(Request $request): array
$this->stopwatch->start('queryUserRelated');
$fid = $result['fid'];
$authorExpGrades = collect($this->authorExpGradeRepository->getLatestOfUsers($fid, $uids))
->keyBy(fn(AuthorExpGrade $authorExpGrade) => $authorExpGrade->getUid());
->keyBy(fn(AuthorExpGrade $authorExpGrade) => $authorExpGrade->uid);
$users->each(fn(User $user) => $user->setCurrentAuthorExpGrade($authorExpGrades[$user->getUid()]));

$forumModerators = collect($this->forumModeratorRepository
->getLatestOfUsers($fid, $users->map(fn(User $user) => $user->getPortrait())))
->keyBy(fn(ForumModerator $forumModerator) => $forumModerator->getPortrait());
->keyBy(fn(ForumModerator $forumModerator) => $forumModerator->portrait);
$users->each(fn(User $user) => $user->setCurrentForumModerator($forumModerators->get($user->getPortrait())));
$this->stopwatch->stop('queryUserRelated');

Expand Down
24 changes: 4 additions & 20 deletions be/src/DTO/User/AuthorExpGrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,11 @@
readonly class AuthorExpGrade
{
public function __construct(
#[ORM\Column, ORM\Id]
private int $uid,
#[ORM\Column, ORM\Id, Ignore]
public int $uid,
#[ORM\Column]
private int $discoveredAt,
public int $discoveredAt,
#[ORM\Column]
private int $authorExpGrade,
public int $authorExpGrade,
) {}

#[Ignore]
public function getUid(): int
{
return $this->uid;
}

public function getDiscoveredAt(): int
{
return $this->discoveredAt;
}

public function getAuthorExpGrade(): int
{
return $this->authorExpGrade;
}
}
24 changes: 4 additions & 20 deletions be/src/DTO/User/ForumModerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,11 @@
readonly class ForumModerator
{
public function __construct(
#[ORM\Column, ORM\Id]
private string $portrait,
#[ORM\Column, ORM\Id, Ignore]
public string $portrait,
#[ORM\Column]
private int $discoveredAt,
public int $discoveredAt,
#[ORM\Column]
private string $moderatorTypes,
public string $moderatorTypes,
) {}

#[Ignore]
public function getPortrait(): string
{
return $this->portrait;
}

public function getDiscoveredAt(): int
{
return $this->discoveredAt;
}

public function getModeratorTypes(): string
{
return $this->moderatorTypes;
}
}
2 changes: 0 additions & 2 deletions be/src/PostsQuery/BaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ protected function setResult(
// remove queries for post types with encoded cursor ',,'
$orderedQueries = $orderedQueries->intersectByKeys($cursorsKeyByPostType);
}
$this->stopwatch->start('initPaginators');
/** @var Collection<string, QueryBuilder> $paginators key by post type */
$paginators = $orderedQueries->each(function (QueryBuilder $qb, string $type) use ($cursorsKeyByPostType) {
$cursors = $cursorsKeyByPostType?->get($type);
Expand All @@ -99,7 +98,6 @@ protected function setResult(
$cursors->mapWithKeys(fn($fieldValue, string $fieldName) =>
$qb->setParameter("cursor_$fieldName", $fieldValue)); // prevent overwriting existing param
});
$this->stopwatch->stop('initPaginators');

$resultsAndHasMorePages = $paginators->map(fn(QueryBuilder $paginator) =>
self::hasQueryResultMorePages($paginator, $this->perPageItems));
Expand Down

0 comments on commit e9b73bb

Please sign in to comment.