Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-01-31 03:26:40 +0300
committerDouwe Maan <douwe@selenight.nl>2017-02-07 01:12:24 +0300
commitc8b63a28afa811881b617546fe94a19378585a04 (patch)
tree2b1bd2e9d52e059de0589a014f518f23e9b71ca3 /lib
parent3aa1264dc6c0de3625bb1a2d6a0ee90140a2f519 (diff)
Improve performance of finding last deployed environment
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/database.rb14
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