Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contributes to:
Translations are loaded using a
java.util.ResourceBundle
. In order to allow to customize translations by providing custom messages in the/usr/local/kitodo/messages
directory, a CustomResourceBundle was already implemented, which first checks whether a corresponding file, e.g.messages_en.properties
exists, and if it exists, uses that for translating messages.In order to access property files outside of the current jar (meaning from the directory
/usr/local/kitodo/messages
), a new URLClassLoader was initizalized upon every call ofgetResourceBundle
, see Line 91, and used to load the resource bundle.Unfortunately, using a new URLClassLoader instance effectively disables caching of resource bundles. That means, upon every translation request, e.g.,
#{msgs.something}
, the resource bundle was loaded again, potentially hundreds of times when displaying large process lists.The proposed pull request changes the implemetation of
CustomResourceBundle
to initialize aURLClassLoader
ideally only once during the lifetime of the webapp, such that resource bundles are fully cached.With caching properly working, loading times improve significantly across all pages of Kitodo, e.g.:
Potential problemsIn order to pass all units tests, where property files are generated at runtime during the test, a fallback was added, which re-creates theURLClassLoader
in case a resource bundle is not found. As a consequence, a Kitodo deployment which does provide a directory/usr/local/kitodo/messages/
but not include a required property file (resource bundle) will check for that resource bundle many times and suffer from the original performance drawbacks. This means:either have no directory/usr/local/kitodo/messages/
(which causes all messages to be loaded from the jar)or have a directory/usr/local/kitodo/messages/
that contains all required property filesIf one property file or resource bundle is missing, the caching will be partially disabled again.Alternatively, we need to update unit tests to not test resource bundles by dynamically creating property files during runtime.
Update 2022-05-03: Unit tests have been updated, which makes the previously suggested fallback obsolete. Resource bundles (property files) are now loaded upon first access. Changes to the property files requires a re-deployment of the web application to take effect.