diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-01-30 18:26:40 -0600 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-02-06 16:12:24 -0600 |
commit | c8b63a28afa811881b617546fe94a19378585a04 (patch) | |
tree | 2b1bd2e9d52e059de0589a014f518f23e9b71ca3 /lib | |
parent | 3aa1264dc6c0de3625bb1a2d6a0ee90140a2f519 (diff) | |
download | gitlab-ce-c8b63a28afa811881b617546fe94a19378585a04.tar.gz |
Improve performance of finding last deployed environment
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/database.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index 55b8f888d53..dc2537d36aa 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -35,6 +35,20 @@ module Gitlab order end + def self.nulls_first_order(field, direction = 'ASC') + order = "#{field} #{direction}" + + if Gitlab::Database.postgresql? + order << ' NULLS FIRST' + else + # `field IS NULL` will be `0` for non-NULL columns and `1` for NULL + # columns. In the (default) ascending order, `0` comes first. + order.prepend("#{field} IS NULL, ") if direction == 'DESC' + end + + order + end + def self.random Gitlab::Database.postgresql? ? "RANDOM()" : "RAND()" end |