Skip to content

Conversation

@michalsn
Copy link
Member

Description
This PR enhances user queries by enabling the retrieval of related user data more efficiently.

It adds two new methods: withGroups() and withPermissions(), which loads user groups and permissions directly when fetching users. The existing withIdentities() method (previously undocumented) has also been included in the documentation.

With these methods, all necessary user information can be loaded in a single query (one per used method), reducing the number of additional queries and improving performance.

The problem this PR solves was described in the Bonfire2 repo: lonnieezell/Bonfire2#558

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

@michalsn michalsn added the enhancement New feature or request label Feb 28, 2025
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! Thanks.

@dgvirtual Please confirm if the issue has been resolved.

@michalsn michalsn force-pushed the withGroupsAndPermissions branch from 665af54 to 5272cc2 Compare July 5, 2025 18:50
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! Thanks.

@michalsn michalsn merged commit 117d461 into codeigniter4:develop Jul 6, 2025
34 checks passed
@michalsn
Copy link
Member Author

michalsn commented Jul 6, 2025

Thanks @datamweb

@michalsn michalsn deleted the withGroupsAndPermissions branch July 6, 2025 07:13
@michalsn michalsn mentioned this pull request Jul 14, 2025
5 tasks
@dgvirtual
Copy link
Contributor

I added in Bonfire2 src\Users\Controllers\UserController:

        $userModel->filter($this->request->getGet('filters'))
            ->withPermissions()
            ->withIdentities()
            ->withGroups();

The withGroups part works (-14 database calls).

The withPermissions part seems to not work: I still get lazy loading on calling
$user->can('users.manage-admins') in view
src\Users\Views\_table.php

@michalsn
Copy link
Member Author

michalsn commented Oct 5, 2025

I guess this may occur when no permissions are set for the user. I will look into it tonight.

@dgvirtual
Copy link
Contributor

dgvirtual commented Oct 5, 2025 via email

@michalsn
Copy link
Member Author

michalsn commented Oct 5, 2025

@dgvirtual Please check #1290 when you get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants