Skip to content
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

Prevent database access in cache:warmup #25

Open
erik-zicht opened this issue Jul 20, 2020 · 2 comments
Open

Prevent database access in cache:warmup #25

erik-zicht opened this issue Jul 20, 2020 · 2 comments
Assignees

Comments

@erik-zicht
Copy link
Contributor

erik-zicht commented Jul 20, 2020

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:

  • Unregister the current Loader in services.xml
  • Write a new command in which the loader is added to the Translator runtime
  • Remove catalogue.<locale>.* from /var/cache/translations
  • Perform a warmup

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

Other solutions:

  • Rewrite the translator internally and don't pre-store our translations but fetch them from the database on demand (and/or implement a memory-cache before requesting database information)
@erik-zicht erik-zicht self-assigned this Jul 20, 2020
@erik-zicht
Copy link
Contributor Author

@7ochem @patrick-zicht

@erik-zicht
Copy link
Contributor Author

erik-zicht commented Aug 3, 2020

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

erik-zicht added a commit that referenced this issue Aug 20, 2020
erik-zicht added a commit that referenced this issue Nov 20, 2020
erik-zicht added a commit that referenced this issue Nov 20, 2020
erik-zicht added a commit that referenced this issue Nov 20, 2020
erik-zicht added a commit that referenced this issue Nov 20, 2020
erik-zicht added a commit that referenced this issue Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant