Skip to content

Add filters to import source users Graphql resolver

What does this MR do and why?

Update the resolver to filter and sort results.

Related to: #455902 (closed)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

  1. Create sample Import::SourceUser records using Rails console
10000.times do 
  status = Import::SourceUser.state_machines[:status].states.map(&:value).sample

  reassign_to_user = [1, 2, 3, 4, 5].include?(status) ? User.where(user_type: 0).order("RANDOM()").limit(1).first : nil
  reassigned_by_user = [1, 2, 3, 4, 5, 6].include?(status) ? User.first : nil

  FactoryBot.create(
    :import_source_user, 
    reassign_to_user: reassign_to_user, 
    reassigned_by_user: reassigned_by_user, 
    namespace: Group.where(parent: nil).order("RANDOM()").limit(1).first, 
    source_name: FFaker::Name.unique.name, 
    source_username: FFaker::Internet.unique.user_name,
    status: status
  )
end
  1. Enable feature flag bulk_import_user_mapping using Rails console
  2. Use http://gdk.test:3000/-/graphql-explorer to test the API
{
  group(fullPath: "toolbox") {
    importSourceUsers(statuses: [AWAITING_APPROVAL, REJECTED], sort: STATUS_ASC, search: "Adr") {
     	nodes {
        id
        status
        sourceName
        sourceUsername
        placeholderUser {
          id
          name
        }
        reassignedByUser {
          id
          name
        }
        reassignToUser {
          id
          name
        }
      } 
    }
  }
}

SQL queries

SQL 1

Raw SQL
SELECT
    "import_source_users".*
FROM
    "import_source_users"
WHERE
    "import_source_users"."namespace_id" = 22
ORDER BY
    "import_source_users"."source_name" ASC,
    "import_source_users"."id" DESC
LIMIT 101

Query plan: https://explain.depesz.com/s/igtk

SQL 2

Raw SQL
SELECT
    "import_source_users".*
FROM
    "import_source_users"
WHERE
    "import_source_users"."namespace_id" = 22
    AND "import_source_users"."status" IN (1, 3)
ORDER BY
    "import_source_users"."source_name" ASC,
    "import_source_users"."id" DESC
LIMIT 101

Query plan: https://explain.depesz.com/s/KYqW

SQL 3

Raw SQL
SELECT
    "import_source_users".*
FROM
    "import_source_users"
WHERE
    "import_source_users"."namespace_id" = 22
    AND "import_source_users"."status" IN (1, 3)
    AND ("import_source_users"."source_name" ILIKE '%Adr%'
        OR "import_source_users"."source_username" ILIKE '%Adr%')
ORDER BY
    "import_source_users"."source_name" ASC,
    "import_source_users"."id" DESC
LIMIT 101

Query plan: https://explain.depesz.com/s/6wDX

SQL 4

Raw SQL
SELECT
    "import_source_users".*
FROM
    "import_source_users"
WHERE
    "import_source_users"."namespace_id" = 22
    AND "import_source_users"."status" IN (1, 3)
    AND ("import_source_users"."source_name" ILIKE '%Adr%'
        OR "import_source_users"."source_username" ILIKE '%Adr%')
ORDER BY
    "import_source_users"."status" ASC,
    "import_source_users"."id" DESC
LIMIT 101

Query plan: https://explain.depesz.com/s/lHUx

Edited by Rodrigo Tomonari

Merge request reports

Loading