api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.45k stars 876 forks source link

Merge functionality of PurgeHttpCacheListener and PublishMercureUpdatesListener and enchance #5086

Closed silverbackdan closed 2 years ago

silverbackdan commented 2 years ago

Description
The responsibility of these two listeners originates from the same initial trigger point. A database entity has been updated so we should clear cache and notify of changes.

The PurgeHttpCacheListener has some extended functionality to gather relations as well which the PublishMercureUpdatesListener should probably do as well.

My thoughts would be to create a single listener with the extended functionality that the PurgeHttpCacheListener has. This can collect all the relevant iris and objects to publish on the onFlush and PostFlush event.

A simple change to allow a method to be public, like addTagsFor method, would allow any user to also populate any other resource changes outside of the scope of the doctrine database changes and I think a really neat little addition for lots of flexibility.

the onFlush could have the detection of which services are enabled and available and then purge caches and publish updates accordingly.

In my case... it may be nice to have 2 iri converters in place in the constructor as well, so one can be replaced for mercure if required.

Thoughts on this update much appreciated before the work. Probably includes BC breaks though so... may need to be approached with caution.

silverbackdan commented 2 years ago

Discussed, and too much abstraction. Mercure reflects update and not the API at any given point in time, but cache needs to be in sync with API