Feature PR-5.4-dev Pending

User tests: Successful: Unsuccessful:

avatar sshekhar563
sshekhar563
9 Nov 2025

Pull Request for Issue #46369

This PR introduces caching decorator factories for Forms and Users to restore the performance benefits previously provided by getInstance() methods, without re-adding singletons or causing a BC break.

Summary

Adds CachingFormFactory and CachingUserFactory implementing the existing factory interfaces

Adds CachingFactoriesProvider to register caching wrappers via the DI container

Enables per-request in-memory identity maps for Forms and Users

No modifications to existing factories or interfaces (BC-safe)

Why

The removal of Form::getInstance() and User::getInstance() removed request-level caching, causing:

repeated DB queries for the same User object

repeated parsing/loading of Forms

performance regressions especially for large lists, form fields, and plugins executing multiple lookups

This PR restores the original caching behavior without the global static singleton pattern.
Fixes - #46369

avatar sshekhar563 sshekhar563 - open - 9 Nov 2025
avatar sshekhar563 sshekhar563 - change - 9 Nov 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 9 Nov 2025
Category Libraries
avatar richard67 richard67 - change - 9 Nov 2025
The description was changed
avatar richard67 richard67 - edited - 9 Nov 2025
avatar richard67 richard67 - change - 9 Nov 2025
Title
Add CachingFormFactory and CachingUserFactory with DI provider (BC-safe caching)
[5.4] Add CachingFormFactory and CachingUserFactory with DI provider (BC-safe caching)
avatar richard67 richard67 - edited - 9 Nov 2025
avatar richard67 richard67 - change - 9 Nov 2025
Labels Added: PR-5.4-dev
avatar richard67
richard67 - comment - 9 Nov 2025

@sshekhar563 Please check the code style errors reported in the CI checks (or see here https://github.com/joomla/joomla-cms/actions/runs/19208200451/job/54906507158?pr=46428 ). Thanks in advance.

avatar sshekhar563
sshekhar563 - comment - 9 Nov 2025

Thanks for the heads-up, @richard67
I’ve fixed all reported code style issues and pushed the updated changes.
The php-cs-fixer and phpcs checks should pass now.

avatar richard67
richard67 - comment - 9 Nov 2025

Thanks for the heads-up, @richard67 I’ve fixed all reported code style issues and pushed the updated changes. The php-cs-fixer and phpcs checks should pass now.

@sshekhar563 Code style seems ok now, but PHPstan reports issues. You can see them when checking your changes on GitHub here: https://github.com/joomla/joomla-cms/pull/46428/files and scroll down to the libraries/src/User/CachingUserFactory.phpfile. Please check if you can fix that.

Besides this I see that you place constructor methods before class variables. That's not right, class variables should come first, then the constructor and then other methods. The code style checker might not complain about that, but if you check our other sources you will see it is like that.

avatar brianteeman
brianteeman - comment - 9 Nov 2025

Please look at the other files in these folders and update these new files with the same information in the document headers

avatar richard67
richard67 - comment - 10 Nov 2025

@sshekhar563 Other thing: Could you rebase this PR to the 6.1-dev branch?

We have discussed it in the maintainers Team.

The referred issue #46369 is not an actual issue, it is a reminder that we will have an issue when we will remove the getInstance() methods in a future release, which can be only a major version due to semantic versioning because it would be a b/c break, so it can happen earliest with 7.0, maybe more likely 8.0.

So it makes sense to introduce a replacement before that like your PR here does.

But as that replacement would be a new feature, it cannot be done with a patch release (also due to semantic versioning), so not with 5.4 or 6.0. That's why it should be rebased to (or re-done for) the 6.1-dev branch.

Let me know if you need help with that.

Thanks for your understanding.

avatar sshekhar563 sshekhar563 - change - 12 Nov 2025
Labels Added: Feature
avatar Fedik
Fedik - comment - 12 Nov 2025

@sshekhar563 did you use AI code assistant?
Please review the code to fit it in to Joomla code style. There still many issues with the generated code.

avatar joomla-cms-bot joomla-cms-bot - change - 13 Nov 2025
Category Libraries Repository Libraries
avatar sshekhar563
sshekhar563 - comment - 13 Nov 2025

Thanks for the feedback.
I’ve manually reviewed all three files and updated them to follow Joomla’s core coding style exactly, using the same headers, method order, and formatting as other files in libraries/src/User, Form, and Service.
I also re-ran php-cs-fixer and phpcs, and both now pass cleanly.
Please let me know if you’d like any further adjustments.

Add a Comment

Login with GitHub to post a comment