zicht / messages-bundle

Library - ZichtMessagesBundle - Edit your translations in the database
MIT License
1 stars 0 forks source link

Prevent database access in cache:warmup #25

Open erik-zicht opened 4 years ago

erik-zicht commented 4 years ago

Currently the Zicht\Bundle\MessagesBundle\Translation\Loader needs database access in the cache:clear process to examine which translations are available to add to the overall catalogue for each locale. They will be merged with existing translations and somewhere later dumped to the cache-directory.

This is bad practice, as it makes the applications stateful in a process that should be stateless. A cache-clear should be performed regardless of implementation details such as the database. If the filesystem it will be deployed on supports write-actions, this might be performed at a later stage.

Adding translations in cache-warmup is a sophisticated process traced back to several private methods in Symfony\Bundle\FrameworkBundle\Translation\Translator.

Possible is a workaround such as:

Only problem is a race-condition between normal requests filling the cache again and the execution of this new command.

Other solutions:

erik-zicht commented 4 years ago

@7ochem @patrick-zicht

erik-zicht commented 3 years ago

Check https://github.com/lexik/LexikTranslationBundle, there is a Command that does this, this bundle seems not to be integrated with a cache-warmup.

edit: https://github.com/lexik/LexikTranslationBundle/blob/master/Translation/Loader/DatabaseLoader.php through this loader they run almost the same code as we do in Zicht\Bundle\MessagesBundle\Translation\Loader