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

Use ResultSet::single() or ::first() rather than ::all()? #21

Open
cxw42 opened this issue Dec 7, 2019 · 1 comment
Open

Use ResultSet::single() or ::first() rather than ::all()? #21

cxw42 opened this issue Dec 7, 2019 · 1 comment

Comments

@cxw42
Copy link

cxw42 commented Dec 7, 2019

Thank you for this module, which is working well for me! Looking at the source, I noticed that the user search is generally my ($user) = ...->all():

my ( $user ) = $self->_user_rset( 'username', $username )->all;

my ($user) = $self->_user_rset( pw_reset_code => $code )->all;

my ($user) = $self->_user_rset(username => $username)->all;

my ($user) = $self->_user_rset(username => $username, $options)->all;

DBIx::Class::ResultSet::single() claims to avoid creating a cursor if there's only one result. Since we only keep one result anyway, would it be worth using single() for speed? If not, would you please let me know the details for my own understanding?

Alternatively, would my $user = ...->first improve code clarity?

Thanks for considering this request!

@racke
Copy link
Contributor

racke commented Dec 7, 2019

It would certainly improve the readability of the code. The query should only yield one result, otherwise your database structure / data is somewhat questionable. @cxw42 thanks for the hint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants