-
-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paginators Cache ID is too generic #669
Comments
Maybe implement |
Can you provide a unit test for this? Though your description and the other bug reference are useful, seeing this in code would be most beneficial. |
@TomHAnderson I cant provide a failing unit test because the relevant parts are Working example (Different pages creates different cache id´s) /** @var EntityManager $entityManager */
$entityManager = $container->get(EntityManager::class);
/** @var StorageAdapterFactoryInterface $storageFactory */
$storageFactory = $container->get(StorageAdapterFactoryInterface::class);
$cache = $storageFactory->create(
'filesystem',
[
'cache_dir' => '/var/www/stack/src/crm/data/cache/'
],
[
['name' => 'serializer'],
]
);
$queryBuilder = new QueryBuilder($entityManager);
$queryBuilder
->select('t0')
->from(Entity\City', 't0');
$doctrinePaginator = new DoctrinePaginator($queryBuilder);
$doctrinePaginatorAdapter = new DoctrinePaginatorAdapter($doctrinePaginator);
$paginator = new LaminasPaginator($doctrinePaginatorAdapter);
$paginator::setCache($cache);
$paginator->getItemsByPage(1); //_getCacheId() => Laminas_Paginator_1_07381ecd2347c3ccacd038f34ab9c699
$paginator->getItemsByPage(2); //_getCacheId() => Laminas_Paginator_2_07381ecd2347c3ccacd038f34ab9c699 Failing example (Different where parts creates same cache id`s) /** @var EntityManager $entityManager */
$entityManager = $container->get(EntityManager::class);
/** @var StorageAdapterFactoryInterface $storageFactory */
$storageFactory = $container->get(StorageAdapterFactoryInterface::class);
$cache = $storageFactory->create(
'filesystem',
[
'cache_dir' => '/var/www/stack/src/crm/data/cache/'
],
[
['name' => 'serializer'],
]
);
$queryBuilder1 = new QueryBuilder($entityManager);
$queryBuilder1
->select('t0')
->from('Entity\City', 't0')
->where(
$queryBuilder1->expr()->eq('t0.name', $queryBuilder1->expr()->literal('test'))
);
$doctrinePaginator1 = new DoctrinePaginator($queryBuilder1);
$doctrinePaginatorAdapter1 = new DoctrinePaginatorAdapter($doctrinePaginator1);
$paginator1 = new LaminasPaginator($doctrinePaginatorAdapter1);
$paginator1::setCache($cache);
$queryBuilder2 = new QueryBuilder($entityManager);
$queryBuilder2
->select('t0')
->from('Entity\City', 't0')
->where(
$queryBuilder2->expr()->eq('t0.name', $queryBuilder2->expr()->literal('test2'))
);
$doctrinePaginator2 = new DoctrinePaginator($queryBuilder2);
$doctrinePaginatorAdapter2 = new DoctrinePaginatorAdapter($doctrinePaginator2);
$paginator2 = new LaminasPaginator($doctrinePaginatorAdapter2);
$paginator2::setCache($cache);
$paginator1->getItemsByPage(1); //_getCacheId() => Laminas_Paginator_1_07381ecd2347c3ccacd038f34ab9c699
$paginator2->getItemsByPage(1); //_getCacheId() => Laminas_Paginator_1_07381ecd2347c3ccacd038f34ab9c699
public function jsonSerialize()
{
return [
'select' => $this->paginator->getQuery()->getSQL(),
'count_select' => $this->paginator->count(),
];
} |
Is this the reason you think adding JsonSerilizable will fix the issue? https://github.com/laminas/laminas-paginator/blob/2.11.x/src/Paginator.php#L906 |
Yea, am i wrong? 🤷♂️ |
No! Not at all. I just wanted to be sure we're on the same page. I think your solution of adding JsonSerializable support is a non-intrusive method of fixing the problem you've described. I'd like to go ahead with it. Because you brought up the issue would you like to provide a PR? If not, that's fine and I'll take care of it but I think you should give credit where credit is due. |
I will give it a try in the next few days. 👌 |
Hey there,
it seems like the
_getCacheInternalId()
Method inlaminas-paginator/src/Paginator.php
does create too generic cache ids. I useDoctrinePaginator
with multipleWHERE
parts. The generated cache key is the same as theDoctrinePaginator
withoutWHERE
part.There is an exception for
DbSelect
instances. See laminas/laminas-paginator#6Is there a way to get around this problem?
The text was updated successfully, but these errors were encountered: