Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
gitlab-ce
Commits
912f4704
Commit
912f4704
authored
Sep 16, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ordering issue
parent
1b2a1d0d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
2 deletions
+26
-2
app/models/ci/project.rb
app/models/ci/project.rb
+1
-1
db/migrate/20150916145038_add_index_for_committed_at_and_id.rb
...grate/20150916145038_add_index_for_committed_at_and_id.rb
+5
-0
db/schema.rb
db/schema.rb
+2
-1
spec/models/ci/project_spec.rb
spec/models/ci/project_spec.rb
+18
-0
No files found.
app/models/ci/project.rb
View file @
912f4704
...
...
@@ -33,7 +33,7 @@ module Ci
belongs_to
:gl_project
,
class_name:
'::Project'
,
foreign_key: :gitlab_id
has_many
:commits
,
->
()
{
order
(
:committed_at
)
},
dependent: :destroy
,
class_name:
'Ci::Commit'
has_many
:commits
,
->
()
{
order
(
'CASE WHEN commits.committed_at IS NULL THEN 0 ELSE 1 END'
,
:committed_at
,
:id
)
},
dependent: :destroy
,
class_name:
'Ci::Commit'
has_many
:builds
,
through: :commits
,
dependent: :destroy
,
class_name:
'Ci::Build'
has_many
:runner_projects
,
dependent: :destroy
,
class_name:
'Ci::RunnerProject'
has_many
:runners
,
through: :runner_projects
,
class_name:
'Ci::Runner'
...
...
db/migrate/20150916145038_add_index_for_committed_at_and_id.rb
0 → 100644
View file @
912f4704
class
AddIndexForCommittedAtAndId
<
ActiveRecord
::
Migration
def
change
add_index
:ci_commits
,
[
:project_id
,
:committed_at
,
:id
]
end
end
db/schema.rb
View file @
912f4704
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2015091
4215247
)
do
ActiveRecord
::
Schema
.
define
(
version:
2015091
6145038
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -118,6 +118,7 @@ ActiveRecord::Schema.define(version: 20150914215247) do
t
.
datetime
"committed_at"
end
add_index
"ci_commits"
,
[
"project_id"
,
"committed_at"
,
"id"
],
name:
"index_ci_commits_on_project_id_and_committed_at_and_id"
,
using: :btree
add_index
"ci_commits"
,
[
"project_id"
,
"committed_at"
],
name:
"index_ci_commits_on_project_id_and_committed_at"
,
using: :btree
add_index
"ci_commits"
,
[
"project_id"
,
"sha"
],
name:
"index_ci_commits_on_project_id_and_sha"
,
using: :btree
add_index
"ci_commits"
,
[
"project_id"
],
name:
"index_ci_commits_on_project_id"
,
using: :btree
...
...
spec/models/ci/project_spec.rb
View file @
912f4704
...
...
@@ -61,6 +61,24 @@ describe Ci::Project do
end
end
describe
'ordered commits'
do
let
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
it
'returns ordered list of commits'
do
commit1
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
1
.
hour
.
ago
,
project:
project
commit2
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
2
.
hour
.
ago
,
project:
project
project
.
commits
.
should
==
[
commit2
,
commit1
]
end
it
'returns commits ordered by committed_at and id, with nulls last'
do
commit1
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
1
.
hour
.
ago
,
project:
project
commit2
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
nil
,
project:
project
commit3
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
2
.
hour
.
ago
,
project:
project
commit4
=
FactoryGirl
.
create
:ci_commit
,
committed_at:
nil
,
project:
project
project
.
commits
.
should
==
[
commit2
,
commit4
,
commit3
,
commit1
]
end
end
context
:valid_project
do
let
(
:project
)
{
FactoryGirl
.
create
:ci_project
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment