Skip to content

Refactor memberships query in users controller #312

Closed
@sauloperez

Description

@sauloperez

Now that the user's query also fetches their membership and account, as shown below:

@users = @search
.result(distinct: false)
.joins(members: :account)
.eager_load(members: :account)
.where(members: { organization: current_organization.id })
.page(params[:page])
.per(25)

There's no point in fetching the memberships and building a Hash associating the user and his membership, as shown below:

@memberships = current_organization.members.
where(user_id: @users.map(&:id)).
includes(:account).each_with_object({}) do |mem, ob|
ob[mem.user_id] = mem
end

We already have that information. We simply need to access it directly from each of the user records returned by the first query.

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