Skip to content

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

Open
@cxw42

Description

@cxw42

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions