Skip to content
Snippets Groups Projects

Improve performance of Project.find_with_namespace

Merged yorickpeterse-staging requested to merge project-find-with-namespace-performance into master

This cuts down the query time of Project.find_with_namespace from roughly 250 ms to roughly 15 ms. For PostgreSQL an expression index is added (also when setting up the database), for MySQL the code relies on it being case-insensitive by default (meaning no special index is required).

At the moment the code is using the method case_insensitive_where, but I'd like some feedback on this name. It's a bit long and as @jacobvosmaer stated it's not the same as ActiveRecord's where method (since case_insensitive_where can only operate on a Hash). Some alternative suggestions were iwhere and case_insensitive_match. Personally I'm not a huge fan of case_insensitive_where since it's quite long, though at least it makes its intent quite clear.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
1 class NamespacesProjectsPathLowerIndexes < ActiveRecord::Migration
2 disable_ddl_transaction!
3
4 def up
5 return unless Gitlab::Database.postgresql?
6
7 execute 'CREATE INDEX CONCURRENTLY index_on_namespaces_lower_path ON namespaces (LOWER(path));'
8 execute 'CREATE INDEX CONCURRENTLY index_on_projects_lower_path ON projects (LOWER(path));'
  • @yorickpeterse since we expect to reuse it in several places maybe something short would be oke. I think iwhere or imatch is pretty ok.

  • username-removed-444 Milestone changed to 8.1

    Milestone changed to 8.1

  • @yorickpeterse ping me when MR is ready for merge

  • @dzaporozhets Using iwhere sounds like a plan, I'll update the MR and ping you when done.

  • Maybe ciwhere? To me ci is more obvious for this.

  • @haynes "ci" is used as a prefix for Continuous Integration all over the place, so that's confusing.

  • Added 3 commits:

    • dfce0add - Revamp finding projects by namespaces
    • 1f6571b6 - Added dedicated Rake task for setting up Postgres
    • dbbabdaf - Added changelog for project namespace performance
  • @DouweM ah right. I didn't think about that.

  • Added 3 commits:

    • 084f9480 - Revamp finding projects by namespaces
    • eb389f80 - Added dedicated Rake task for setting up Postgres
    • be5b98df - Added changelog for project namespace performance
  • Added 3 commits:

    • 03417456 - Revamp finding projects by namespaces
    • c8f18fc5 - Added dedicated Rake task for setting up Postgres
    • 2d779f70 - Added changelog for project namespace performance
  • @dzaporozhets Now that I fixed some Rubocop/spec problems this is good to go from my end.

  • mentioned in merge request !1545 (merged)

  • username-removed-444 Status changed to merged

    Status changed to merged

  • mentioned in issue #3229 (closed)

  • Please register or sign in to reply
    Loading