Skip to content

Improve performance of Project.find_with_namespace

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