diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-07-19 17:03:50 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-07-28 14:31:51 +0300 |
commit | 6ef87a20832d1a2581cb85e60eda46f999c55a81 (patch) | |
tree | 580dfa4039580675f423290ae70acec52b21b9b3 | |
parent | 8626cdc3b3fcb18447c65588327a7d7c16121305 (diff) |
Merge issuable "reopened" state into "opened"
Having two states that essentially mean the same thing is very much like
having a boolean "true" and boolean "mostly-true": it's rather silly.
This commit merges the "reopened" state into the "opened" state while
taking care of system notes still showing messages along the lines of
"Alice reopened this issue".
A big benefit from having only two states (opened and closed) is that
indexing and querying becomes simpler and more performant. For example,
to get all the opened queries we no longer have to query both states:
SELECT *
FROM issues
WHERE project_id = 2
AND state IN ('opened', 'reopened');
Instead we can query a single state directly, which can be much faster:
SELECT *
FROM issues
WHERE project_id = 2
AND state = 'opened';
Further, only having two states makes indexing easier as we will only
ever filter (and thus scan an index) using a single value. Partial
indexes could help but aren't supported on MySQL, complicating the
development process and not being helpful for MySQL.
21 files changed, 65 insertions, 49 deletions
diff --git a/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js b/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js index 72a13108404..fddafb0ddfa 100644 --- a/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js +++ b/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js @@ -65,7 +65,7 @@ export default class MergeRequestStore { this.mergeCheckPath = data.merge_check_path; this.mergeActionsContentPath = data.commit_change_content_path; this.isRemovingSourceBranch = this.isRemovingSourceBranch || false; - this.isOpen = data.state === 'opened' || data.state === 'reopened' || false; + this.isOpen = data.state === 'opened'; this.hasMergeableDiscussionsState = data.mergeable_discussions_state === false; this.canRemoveSourceBranch = currentUser.can_remove_source_branch || false; this.canMerge = !!data.merge_path; diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index 6fe17a2b99d..08a843ada97 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -81,7 +81,6 @@ class IssuableFinder end counts[:all] = counts.values.sum - counts[:opened] += counts[:reopened] counts end diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 13fe9d09c69..935ffe343ff 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -71,9 +71,8 @@ module Issuable scope :of_projects, ->(ids) { where(project_id: ids) } scope :of_milestones, ->(ids) { where(milestone_id: ids) } scope :with_milestone, ->(title) { left_joins_milestones.where(milestones: { title: title }) } - scope :opened, -> { with_state(:opened, :reopened) } + scope :opened, -> { with_state(:opened) } scope :only_opened, -> { with_state(:opened) } - scope :only_reopened, -> { with_state(:reopened) } scope :closed, -> { with_state(:closed) } scope :left_joins_milestones, -> { joins("LEFT OUTER JOIN milestones ON #{table_name}.milestone_id = milestones.id") } @@ -234,7 +233,7 @@ module Issuable end def open? - opened? || reopened? + opened? end def user_notes_count diff --git a/app/models/issue.rb b/app/models/issue.rb index 400bb55d2f0..1c948c8957e 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -62,15 +62,14 @@ class Issue < ActiveRecord::Base state_machine :state, initial: :opened do event :close do - transition [:reopened, :opened] => :closed + transition [:opened] => :closed end event :reopen do - transition closed: :reopened + transition closed: :opened end state :opened - state :reopened state :closed before_transition any => :closed do |issue| diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index a910099b4c1..81e0776e79c 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -42,23 +42,23 @@ class MergeRequest < ActiveRecord::Base state_machine :state, initial: :opened do event :close do - transition [:reopened, :opened] => :closed + transition [:opened] => :closed end event :mark_as_merged do - transition [:reopened, :opened, :locked] => :merged + transition [:opened, :locked] => :merged end event :reopen do - transition closed: :reopened + transition closed: :opened end event :lock_mr do - transition [:reopened, :opened] => :locked + transition [:opened] => :locked end event :unlock_mr do - transition locked: :reopened + transition locked: :opened end after_transition any => :locked do |merge_request, transition| @@ -72,7 +72,6 @@ class MergeRequest < ActiveRecord::Base end state :opened - state :reopened state :closed state :merged state :locked @@ -368,7 +367,7 @@ class MergeRequest < ActiveRecord::Base errors.add :branch_conflict, "You can not use same project/branch for source and target" end - if opened? || reopened? + if opened? similar_mrs = self.target_project.merge_requests.where(source_branch: source_branch, target_branch: target_branch, source_project_id: source_project.try(:id)).opened similar_mrs = similar_mrs.where('id not in (?)', self.id) if self.id if similar_mrs.any? diff --git a/app/models/project_services/drone_ci_service.rb b/app/models/project_services/drone_ci_service.rb index f6cade9c290..c93f1632652 100644 --- a/app/models/project_services/drone_ci_service.rb +++ b/app/models/project_services/drone_ci_service.rb @@ -114,7 +114,7 @@ class DroneCiService < CiService end def merge_request_valid?(data) - %w(opened reopened).include?(data[:object_attributes][:state]) && + data[:object_attributes][:state] == 'opened' && data[:object_attributes][:merge_status] == 'unchecked' end end diff --git a/app/services/issues/reopen_service.rb b/app/services/issues/reopen_service.rb index 73b2e85cba3..35de4337b15 100644 --- a/app/services/issues/reopen_service.rb +++ b/app/services/issues/reopen_service.rb @@ -5,7 +5,7 @@ module Issues if issue.reopen event_service.reopen_issue(issue, current_user) - create_note(issue) + create_note(issue, 'reopened') notification_service.reopen_issue(issue, current_user) execute_hooks(issue, 'reopen') invalidate_cache_counts(issue, users: issue.assignees) @@ -16,8 +16,8 @@ module Issues private - def create_note(issue) - SystemNoteService.change_status(issue, issue.project, current_user, issue.state, nil) + def create_note(issue, state = issue.state) + SystemNoteService.change_status(issue, issue.project, current_user, state, nil) end end end diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb index 3542a41ac83..35ccff26262 100644 --- a/app/services/merge_requests/base_service.rb +++ b/app/services/merge_requests/base_service.rb @@ -1,7 +1,7 @@ module MergeRequests class BaseService < ::IssuableBaseService - def create_note(merge_request) - SystemNoteService.change_status(merge_request, merge_request.target_project, current_user, merge_request.state, nil) + def create_note(merge_request, state = merge_request.state) + SystemNoteService.change_status(merge_request, merge_request.target_project, current_user, state, nil) end def create_title_change_note(issuable, old_title) @@ -44,7 +44,7 @@ module MergeRequests end # Returns all origin and fork merge requests from `@project` satisfying passed arguments. - def merge_requests_for(source_branch, mr_states: [:opened, :reopened]) + def merge_requests_for(source_branch, mr_states: [:opened]) MergeRequest .with_state(mr_states) .where(source_branch: source_branch, source_project_id: @project.id) diff --git a/app/services/merge_requests/reopen_service.rb b/app/services/merge_requests/reopen_service.rb index 52f6d511f98..b9c65be36ec 100644 --- a/app/services/merge_requests/reopen_service.rb +++ b/app/services/merge_requests/reopen_service.rb @@ -5,7 +5,7 @@ module MergeRequests if merge_request.reopen event_service.reopen_mr(merge_request, current_user) - create_note(merge_request) + create_note(merge_request, 'reopened') notification_service.reopen_mr(merge_request, current_user) execute_hooks(merge_request, 'reopen') merge_request.reload_diff(current_user) diff --git a/changelogs/unreleased/merge-issuable-reopened-into-opened-state.yml b/changelogs/unreleased/merge-issuable-reopened-into-opened-state.yml new file mode 100644 index 00000000000..5d7af8971e5 --- /dev/null +++ b/changelogs/unreleased/merge-issuable-reopened-into-opened-state.yml @@ -0,0 +1,4 @@ +--- +title: Merge issuable "reopened" state into "opened" +merge_request: +author: diff --git a/db/post_migrate/20170719150301_merge_issuable_reopened_into_opened_state.rb b/db/post_migrate/20170719150301_merge_issuable_reopened_into_opened_state.rb new file mode 100644 index 00000000000..acc0fc7a0ac --- /dev/null +++ b/db/post_migrate/20170719150301_merge_issuable_reopened_into_opened_state.rb @@ -0,0 +1,32 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class MergeIssuableReopenedIntoOpenedState < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + class Issue < ActiveRecord::Base + self.table_name = 'issues' + + include EachBatch + end + + class MergeRequest < ActiveRecord::Base + self.table_name = 'merge_requests' + + include EachBatch + end + + def up + [Issue, MergeRequest].each do |model| + say "Changing #{model.table_name}.state from 'reopened' to 'opened'" + + model.where(state: 'reopened').each_batch do |batch| + batch.update_all(state: 'opened') + end + end + end +end diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index f1fd1fd7f73..a16695cb7c1 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -16,12 +16,8 @@ FactoryGirl.define do state :closed end - trait :reopened do - state :reopened - end - factory :closed_issue, traits: [:closed] - factory :reopened_issue, traits: [:reopened] + factory :reopened_issue, traits: [:opened] factory :labeled_issue do transient do diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index 253a025af48..1bc530d06db 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -44,10 +44,6 @@ FactoryGirl.define do state :opened end - trait :reopened do - state :reopened - end - trait :locked do state :locked end @@ -74,7 +70,7 @@ FactoryGirl.define do factory :merged_merge_request, traits: [:merged] factory :closed_merge_request, traits: [:closed] - factory :reopened_merge_request, traits: [:reopened] + factory :reopened_merge_request, traits: [:opened] factory :merge_request_with_diffs, traits: [:with_diffs] factory :merge_request_with_diff_notes do after(:create) do |mr| diff --git a/spec/lib/banzai/filter/issuable_state_filter_spec.rb b/spec/lib/banzai/filter/issuable_state_filter_spec.rb index 7cf2f4282f8..bc7cae1df8d 100644 --- a/spec/lib/banzai/filter/issuable_state_filter_spec.rb +++ b/spec/lib/banzai/filter/issuable_state_filter_spec.rb @@ -107,14 +107,6 @@ describe Banzai::Filter::IssuableStateFilter do expect(doc.css('a').last.text).to eq(issue.to_reference) end - it 'ignores reopened issue references' do - issue = create_issue(:reopened) - link = create_link(issue.to_reference, issue: issue.id, reference_type: 'issue') - doc = filter(link, context) - - expect(doc.css('a').last.text).to eq(issue.to_reference) - end - it 'appends state to closed issue references' do link = create_link(closed_issue.to_reference, issue: closed_issue.id, reference_type: 'issue') doc = filter(link, context) @@ -139,7 +131,7 @@ describe Banzai::Filter::IssuableStateFilter do end it 'ignores reopened merge request references' do - merge_request = create_merge_request(:reopened) + merge_request = create_merge_request(:opened) link = create_link( merge_request.to_reference, diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index 33cea02153e..2c44be4e447 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -1259,7 +1259,7 @@ describe API::Issues do put api("/projects/#{project.id}/issues/#{closed_issue.iid}", user), state_event: 'reopen' expect(response).to have_http_status(200) - expect(json_response['state']).to eq 'reopened' + expect(json_response['state']).to eq 'opened' end context 'when an admin or owner makes the request' do diff --git a/spec/requests/api/v3/issues_spec.rb b/spec/requests/api/v3/issues_spec.rb index cc81922697a..4dff09b6df8 100644 --- a/spec/requests/api/v3/issues_spec.rb +++ b/spec/requests/api/v3/issues_spec.rb @@ -1114,7 +1114,7 @@ describe API::V3::Issues do put v3_api("/projects/#{project.id}/issues/#{closed_issue.id}", user), state_event: 'reopen' expect(response).to have_http_status(200) - expect(json_response['state']).to eq 'reopened' + expect(json_response['state']).to eq 'opened' end context 'when an admin or owner makes the request' do diff --git a/spec/services/boards/issues/list_service_spec.rb b/spec/services/boards/issues/list_service_spec.rb index 2c293088097..b1b5d807a78 100644 --- a/spec/services/boards/issues/list_service_spec.rb +++ b/spec/services/boards/issues/list_service_spec.rb @@ -20,7 +20,7 @@ describe Boards::Issues::ListService do let!(:opened_issue1) { create(:labeled_issue, project: project, labels: [bug]) } let!(:opened_issue2) { create(:labeled_issue, project: project, labels: [p2]) } - let!(:reopened_issue1) { create(:issue, :reopened, project: project) } + let!(:reopened_issue1) { create(:issue, :opened, project: project) } let!(:list1_issue1) { create(:labeled_issue, project: project, labels: [p2, development]) } let!(:list1_issue2) { create(:labeled_issue, project: project, labels: [development]) } diff --git a/spec/services/boards/issues/move_service_spec.rb b/spec/services/boards/issues/move_service_spec.rb index 7dd1a601700..15a32350ae2 100644 --- a/spec/services/boards/issues/move_service_spec.rb +++ b/spec/services/boards/issues/move_service_spec.rb @@ -73,7 +73,7 @@ describe Boards::Issues::MoveService do issue.reload expect(issue.labels).to contain_exactly(bug, testing) - expect(issue).to be_reopened + expect(issue).to be_opened end end diff --git a/spec/services/delete_merged_branches_service_spec.rb b/spec/services/delete_merged_branches_service_spec.rb index 954c5d3ab73..4b872d667cf 100644 --- a/spec/services/delete_merged_branches_service_spec.rb +++ b/spec/services/delete_merged_branches_service_spec.rb @@ -43,7 +43,7 @@ describe DeleteMergedBranchesService do context 'open merge requests' do it 'does not delete branches from open merge requests' do fork_link = create(:forked_project_link, forked_from_project: project) - create(:merge_request, :reopened, source_project: project, target_project: project, source_branch: 'branch-merged', target_branch: 'master') + create(:merge_request, :opened, source_project: project, target_project: project, source_branch: 'branch-merged', target_branch: 'master') create(:merge_request, :opened, source_project: fork_link.forked_to_project, target_project: project, target_branch: 'improve/awesome', source_branch: 'master') service.execute diff --git a/spec/services/merge_requests/get_urls_service_spec.rb b/spec/services/merge_requests/get_urls_service_spec.rb index 4a7d8ab4c6c..672d86e4028 100644 --- a/spec/services/merge_requests/get_urls_service_spec.rb +++ b/spec/services/merge_requests/get_urls_service_spec.rb @@ -78,7 +78,7 @@ describe MergeRequests::GetUrlsService do end context 'pushing to existing branch and merge request is reopened' do - let!(:merge_request) { create(:merge_request, :reopened, source_project: project, source_branch: source_branch) } + let!(:merge_request) { create(:merge_request, :opened, source_project: project, source_branch: source_branch) } let(:changes) { existing_branch_changes } it_behaves_like 'show_merge_request_url' end diff --git a/spec/services/merge_requests/reopen_service_spec.rb b/spec/services/merge_requests/reopen_service_spec.rb index ce1e9f2ff45..f02af0c582e 100644 --- a/spec/services/merge_requests/reopen_service_spec.rb +++ b/spec/services/merge_requests/reopen_service_spec.rb @@ -28,7 +28,7 @@ describe MergeRequests::ReopenService do end it { expect(merge_request).to be_valid } - it { expect(merge_request).to be_reopened } + it { expect(merge_request).to be_opened } it 'executes hooks with reopen action' do expect(service).to have_received(:execute_hooks) |