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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
26f40aef
Commit
26f40aef
authored
Feb 13, 2019
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code improvements
parent
e2aa3325
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
25 deletions
+18
-25
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+9
-0
app/models/concerns/issuable_states.rb
app/models/concerns/issuable_states.rb
+1
-20
app/models/merge_request.rb
app/models/merge_request.rb
+4
-1
db/migrate/20190211131150_add_state_id_to_issuables.rb
db/migrate/20190211131150_add_state_id_to_issuables.rb
+4
-4
No files found.
app/models/concerns/issuable.rb
View file @
26f40aef
...
...
@@ -132,6 +132,15 @@ module Issuable
fuzzy_search
(
query
,
[
:title
])
end
# Available state values persisted in state_id column using state machine
#
# Override this on subclasses if different states are needed
#
# Check MergeRequest.available_states for example
def
available_states
@available_states
||=
{
opened:
1
,
closed:
2
}.
with_indifferent_access
end
# Searches for records with a matching title or description.
#
# This method uses ILIKE on PostgreSQL and LIKE on MySQL.
...
...
app/models/concerns/issuable_states.rb
View file @
26f40aef
# frozen_string_literal: true
# == IssuableStates concern
#
# Defines states shared by issuables which are persisted on state_id column
# using the state machine.
#
# Used by EE::Epic, Issue and MergeRequest
#
module
IssuableStates
extend
ActiveSupport
::
Concern
# Override this constant on model where different states are needed
# Check MergeRequest::AVAILABLE_STATES
AVAILABLE_STATES
=
{
opened:
1
,
closed:
2
}.
freeze
class_methods
do
def
states
@states
||=
OpenStruct
.
new
(
self
::
AVAILABLE_STATES
)
end
end
# The state:string column is being migrated to state_id:integer column
# This is a temporary hook to populate state_id column with new values
# and can be removed after the state column is removed.
...
...
@@ -30,7 +11,7 @@ module IssuableStates
def
set_state_id
return
if
state
.
nil?
||
state
.
empty?
states_hash
=
self
.
class
.
states
.
to_h
.
with_indifferent_acces
s
states_hash
=
self
.
class
.
available_state
s
self
.
state_id
=
states_hash
[
state
]
end
...
...
app/models/merge_request.rb
View file @
26f40aef
...
...
@@ -22,7 +22,6 @@ class MergeRequest < ActiveRecord::Base
self
.
reactive_cache_lifetime
=
10
.
minutes
SORTING_PREFERENCE_FIELD
=
:merge_requests_sort
AVAILABLE_STATES
=
AVAILABLE_STATES
.
merge
(
merged:
3
,
locked:
4
).
freeze
ignore_column
:locked_at
,
:ref_fetched
,
...
...
@@ -194,6 +193,10 @@ class MergeRequest < ActiveRecord::Base
'!'
end
def
self
.
available_states
@states
||=
super
.
merge
(
locked:
3
,
merged:
4
)
end
def
rebase_in_progress?
strong_memoize
(
:rebase_in_progress
)
do
# The source project can be deleted
...
...
db/migrate/20190211131150_add_state_id_to_issuables.rb
View file @
26f40aef
...
...
@@ -8,9 +8,9 @@ class AddStateIdToIssuables < ActiveRecord::Migration[5.0]
# 2019-02-12 Gitlab.com issuable numbers
# issues count: 13587305
# merge requests count: 18925274
# Using this
50000 as batch size should take around 13
hours
# Using this
25000 as batch size should take around 26
hours
# to migrate both issues and merge requests
BATCH_SIZE
=
50
000
BATCH_SIZE
=
25
000
DELAY_INTERVAL
=
5
.
minutes
.
to_i
class
Issue
<
ActiveRecord
::
Base
...
...
@@ -26,8 +26,8 @@ class AddStateIdToIssuables < ActiveRecord::Migration[5.0]
end
def
up
add_column
:issues
,
:state_id
,
:integer
,
limit:
1
add_column
:merge_requests
,
:state_id
,
:integer
,
limit:
1
add_column
:issues
,
:state_id
,
:integer
,
limit:
2
add_column
:merge_requests
,
:state_id
,
:integer
,
limit:
2
# Is this safe?
# Added to avoid an warning about jobs running inside transactions.
...
...
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