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

perf: refactor Auth #908

Merged
merged 6 commits into from
Oct 21, 2023
Merged

perf: refactor Auth #908

merged 6 commits into from
Oct 21, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Oct 16, 2023

Description
See #905 (reply in thread)

  • to reduce the number of loaded files
    • in the current code, service('auth')->routes($routes) creates Authentication and UserModel instances.

Before:
Screenshot 2023-10-16 18 11 51

After:
Screenshot 2023-10-16 18 10 58

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added breaking change Pull requests that may break existing functionalities refactor Pull requests that refactor code labels Oct 16, 2023
@datamweb
Copy link
Collaborator

datamweb commented Oct 16, 2023

@kenjis, we can use command php spark sheild:setup to set the value of $collectors. In this way, we allow the user to cancel the load of Auth collector in Debugbar even in the mode of development. Why not act like what we did for the helpers!

OR
Config/Auth.php:

/**
* --------------------------------------------------------------------
* Load of Auth collector in Debugbar
* --------------------------------------------------------------------
* By default, Auth in Debugbar is loaded in mode `development`. 
* If you want Auth in Debugbar not to be loaded even in `development` mode,
* set the `false`.
*/
public bool $showAuthInDebugbar = true;

Config/Registrar.php:

    public static function Toolbar(): array
    {
        return (config('Auth')->showAuthInDebugbar) ?
        [
            'collectors' => [
                Auth::class,
            ],
        ] : [];
    }

@datamweb
Copy link
Collaborator

datamweb commented Oct 16, 2023

And another thing that got me thinking is if we can check if the file APPPATH\Config\Auth.php exists, if it does then the file VENDORPATH\codeigniter4\shield\src\Config\Auth.php does not load
Is this reasonable?

Screenshot 2023-10-16 151600

@kenjis
Copy link
Member Author

kenjis commented Oct 16, 2023

Config\Auth extends Shield\Config\Auth. So both are always loaded.

Copy link
Collaborator

@datamweb datamweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
I fell in love with this PR 😊.

@kenjis kenjis merged commit 47cf8c1 into codeigniter4:develop Oct 21, 2023
29 checks passed
@kenjis kenjis deleted the perf-Auth branch October 21, 2023 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Pull requests that may break existing functionalities refactor Pull requests that refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants