Skip to content

Commit

Permalink
Consent listing performance - configurable max items count
Browse files Browse the repository at this point in the history
- added ENV variable `GRID_COUNT_LIMIT`
- count query is by default limited do 100.000 items
  • Loading branch information
tg666 committed Sep 20, 2023
1 parent 6123046 commit bc6c8ca
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# SENTRY_DSN=https://[email protected]/project-id
# GTM_CONTAINER_ID=GTM-XXXXXX # optional
# API_DOCS_ENABLED=1 # optional
# GRID_COUNT_LIMIT=100000 # optional
########################################################################################################################

APP_DEBUG=1
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Added ENV variable `GRID_COUNT_LIMIT`.

### Changed

- The maximum number of entries in the consent list is limited to one million due to performance issues.
- The maximum number of entries in the consent list is limited to value of the ENV variable `GRID_COUNT_LIMIT` due to performance issues (default 100.000).

## 0.10.0 - 2023-08-31

Expand Down
6 changes: 5 additions & 1 deletion config/services.neon
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ services:
- App\Web\AdminModule\ImportModule\Control\ImportModal\ImportModalControlFactoryInterface

# Web\AdminModule\ProjectModule
- App\Web\AdminModule\ProjectModule\Control\ConsentList\ConsentListControlFactoryInterface
-
implement: App\Web\AdminModule\ProjectModule\Control\ConsentList\ConsentListControlFactoryInterface
arguments:
countLimit: ::env(GRID_COUNT_LIMIT|int, 100000)

- App\Web\AdminModule\ProjectModule\Control\ConsentSettingsList\ConsentSettingsListControlFactoryInterface
- App\Web\AdminModule\ProjectModule\Control\ConsentHistory\ConsentHistoryControlFactoryInterface
- App\Web\AdminModule\ProjectModule\Control\ConsentHistory\ConsentHistoryModalControlFactoryInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function () use ($query): DbalQueryBuilder {
->select('1')
->from('consent', 'c')
->andWhere('c.project_id = :projectId')
->setMaxResults(ConsentsDataGridQuery::COUNT_LIMIT)
->setMaxResults($query->getCountLimit())
->setParameter('projectId', $query->projectId());
},
function () use ($query): DbalQueryBuilder {
Expand Down
14 changes: 11 additions & 3 deletions src/ReadModel/Consent/ConsentsDataGridQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@

final class ConsentsDataGridQuery extends AbstractDataGridQuery
{
public const COUNT_LIMIT = 1_000_000;
private const DEFAULT_COUNT_LIMIT = 100_000;

public static function create(string $projectId): self
{
public static function create(
string $projectId,
?int $countLimit = null,
): self {
return self::fromParameters([
'project_id' => $projectId,
'count_limit' => $countLimit,
]);
}

public function projectId(): string
{
return $this->getParam('project_id');
}

public function getCountLimit(): int
{
return $this->getParam('count_limit') ?? self::DEFAULT_COUNT_LIMIT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,24 @@ public function __construct(
private readonly ConsentHistoryModalControlFactoryInterface $consentHistoryModalControlFactory,
private readonly ConsentSettingsDetailModalControlFactoryInterface $consentSettingsDetailModalControlFactory,
private readonly QueryBusInterface $queryBus,
private readonly ?int $countLimit = null,
) {}

/**
* @throws DataGridException
*/
protected function createComponentGrid(): DataGrid
{
$grid = $this->dataGridFactory->create(ConsentsDataGridQuery::create($this->projectId->toString()));
$query = ConsentsDataGridQuery::create(
projectId: $this->projectId->toString(),
countLimit: $this->countLimit,
);
$grid = $this->dataGridFactory->create($query);

$grid->setSessionNamePostfix('p' . $this->projectId->toString());
$grid->setTranslator($this->getPrefixedTranslator());
$grid->setTemplateFile(__DIR__ . '/templates/datagrid.latte');
$grid->addTemplateVariable('paginatorMaxItemsCount', ConsentsDataGridQuery::COUNT_LIMIT);
$grid->addTemplateVariable('paginatorMaxItemsCount', $query->getCountLimit());

$grid->setDefaultSort([
'last_update_at' => 'DESC',
Expand Down Expand Up @@ -76,10 +81,10 @@ protected function createComponentGrid(): DataGrid
$dataModel = $grid->getDataModel();

if (null !== $dataModel) {
$dataModel->onAfterPaginated[] = function (ReadModelDataSource $dataSource) use ($grid): void {
$dataModel->onAfterPaginated[] = function (ReadModelDataSource $dataSource) use ($grid, $query): void {
$paginator = $grid->getPaginator()?->getPaginator();

if (null === $paginator || $paginator->getItemCount() < ConsentsDataGridQuery::COUNT_LIMIT || !$paginator->isLast()) {
if (null === $paginator || $paginator->getItemCount() < $query->getCountLimit() || !$paginator->isLast()) {
return;
}

Expand Down

0 comments on commit bc6c8ca

Please sign in to comment.