Skip to content

Commit c2d9b81

Browse files
Additional orders allows PG to use indexes (#1075)
1 parent fdbe6b2 commit c2d9b81

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/travis/api/v3/queries/repository.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ def find!
4444
def by_slug
4545
owner_name, repo_name = slug.split('/')
4646
Models::Repository.where(
47-
"(lower(vcs_slug) = ? "\
47+
"(lower(repositories.vcs_slug) = ? "\
4848
"or (lower(repositories.owner_name) = ? and lower(repositories.name) = ?)) "\
4949
"and lower(repositories.vcs_type) = ? "\
5050
"and repositories.invalidated_at is null",
5151
slug.downcase,
5252
owner_name.downcase,
5353
repo_name.downcase,
5454
provider.downcase + 'repository'
55-
).order("updated_at desc").first
55+
).order("updated_at desc, vcs_slug asc, owner_name asc, name asc, vcs_type asc").first
5656
end
5757

5858
def provider

lib/travis/model/repository.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Repository < Travis::Model
7676
without_invalidated.where(
7777
"(LOWER(repositories.owner_name) = ? AND LOWER(repositories.name) = ?) OR LOWER(vcs_slug) = ?",
7878
owner_name.downcase, repo_name.downcase, "#{slug.downcase}"
79-
).order('id DESC')
79+
).order('id DESC, owner_name ASC, name ASC, vcs_slug ASC')
8080
}
8181
scope :search, ->(query) {
8282
query = query.gsub('\\', '/')

0 commit comments

Comments
 (0)