core
core copied to clipboard
Out-of-memory exception caused by PurgeHttpCacheListener.php
API Platform version(s) affected: 2.6.6
Description
When a entity is flushed, the vendor/api-platform/core/src/Bridge/Doctrine/EventListener/PurgeHttpCacheListener.php calls gatherRelationTags wich causes a out-of-memory exception on a large entity (an entity with arround 10k related resources)
How to reproduce
- Create 2 entities and relate them with a OneToMany relation. Create a fixture to add 10k items to it.
- Enable the http_cache invalidation (YAML format provided bellow)
api_platform:
http_cache:
invalidation:
enabled: true
- Try to update the entity, this will produce an out-of-memory exception.
Possible Solution
Are there any suggestions or tips? Or is this something that should be fixed in Api Platform?
We still want to make it available as subresource so removing the inversed relation is not an option. Maybe its possible when the entity is flushed to fetch its relations paginated and purge in chunks? Or maybe don't purge the related tasks at all since the child entity is not modified if i'm not wrong.
Additional Context
Our use case:
We have a Task entity and a TaskList entity. A TaskList hasMany Tasks, but a Task hasOne TaskList.
A customer has arround 10k tasks related to a TaskList (also contains completed tasks so it gets larger every day).
Kind regards, Sherin
I think that you should implement your own logic for now, indeed invalidating relations is a part of our algorithm to make sure that everything is invalidated. We can't know forehand that this it's possible for you to not invalidate these :/. My suggestion would be to override this service for the tasks.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.