diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-03 15:08:45 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-03 15:08:45 +0000 |
commit | 55693cc1ec8ac79444bc7214d2812a4ac41bf043 (patch) | |
tree | c9e9df7be9eac5dd1ea71f65da9a6831834b08c4 | |
parent | c089cf73c2f1835dc68fd6107d6cbd10fc17f365 (diff) | |
download | gitlab-ce-55693cc1ec8ac79444bc7214d2812a4ac41bf043.tar.gz |
Add latest changes from gitlab-org/gitlab@master
-rw-r--r-- | app/finders/pipelines_finder.rb | 2 | ||||
-rw-r--r-- | app/services/issuable/clone/attributes_rewriter.rb | 40 | ||||
-rw-r--r-- | changelogs/unreleased/195888-import_to_find_group_objects_within_all_group_ancestors.yml | 5 | ||||
-rw-r--r-- | changelogs/unreleased/37745-optimize-pipelines-finder.yml | 5 | ||||
-rw-r--r-- | changelogs/unreleased/ab-projects-api-remove-unneeded-indexes.yml | 5 | ||||
-rw-r--r-- | danger/roulette/Dangerfile | 4 | ||||
-rw-r--r-- | db/migrate/20200130161817_drop_unneeded_indexes_for_projects_api_requests.rb | 31 | ||||
-rw-r--r-- | db/schema.rb | 7 | ||||
-rw-r--r-- | doc/development/contributing/style_guides.md | 4 | ||||
-rw-r--r-- | doc/development/go_guide/index.md | 6 | ||||
-rw-r--r-- | doc/fixtures/gitlab_tanuki.png | bin | 2545 -> 0 bytes | |||
-rw-r--r-- | doc/user/markdown.md | 5 | ||||
-rw-r--r-- | lib/gitlab/import_export/group_project_object_builder.rb | 6 | ||||
-rw-r--r-- | spec/controllers/help_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/group_project_object_builder_spec.rb | 24 |
15 files changed, 110 insertions, 36 deletions
diff --git a/app/finders/pipelines_finder.rb b/app/finders/pipelines_finder.rb index 48da44123f6..0599daab564 100644 --- a/app/finders/pipelines_finder.rb +++ b/app/finders/pipelines_finder.rb @@ -39,7 +39,7 @@ class PipelinesFinder # rubocop: disable CodeReuse/ActiveRecord def from_ids(ids) - pipelines.unscoped.where(id: ids) + pipelines.unscoped.where(project_id: project.id, id: ids) end # rubocop: enable CodeReuse/ActiveRecord diff --git a/app/services/issuable/clone/attributes_rewriter.rb b/app/services/issuable/clone/attributes_rewriter.rb index 334e50c0be5..2b436f6322c 100644 --- a/app/services/issuable/clone/attributes_rewriter.rb +++ b/app/services/issuable/clone/attributes_rewriter.rb @@ -12,7 +12,7 @@ module Issuable def execute update_attributes = { labels: cloneable_labels } - milestone = cloneable_milestone + milestone = matching_milestone(original_entity.milestone&.title) update_attributes[:milestone] = milestone if milestone.present? new_entity.update(update_attributes) @@ -23,11 +23,8 @@ module Issuable private - def cloneable_milestone - return unless new_entity.supports_milestone? - - title = original_entity.milestone&.title - return unless title + def matching_milestone(title) + return if title.blank? || !new_entity.supports_milestone? params = { title: title, project_ids: new_entity.project&.id, group_ids: group&.id } @@ -49,29 +46,32 @@ module Issuable end def copy_resource_label_events - original_entity.resource_label_events.find_in_batches do |batch| - events = batch.map do |event| - entity_key = new_entity.is_a?(Issue) ? 'issue_id' : 'epic_id' - event.attributes - .except('id', 'reference', 'reference_html') - .merge(entity_key => new_entity.id, 'action' => ResourceLabelEvent.actions[event.action]) - end + entity_key = new_entity.class.name.underscore.foreign_key - Gitlab::Database.bulk_insert(ResourceLabelEvent.table_name, events) + copy_events(ResourceLabelEvent.table_name, original_entity.resource_label_events) do |event| + event.attributes + .except('id', 'reference', 'reference_html') + .merge(entity_key => new_entity.id, 'action' => ResourceLabelEvent.actions[event.action]) end end def copy_resource_weight_events return unless original_entity.respond_to?(:resource_weight_events) - original_entity.resource_weight_events.find_in_batches do |batch| + copy_events(ResourceWeightEvent.table_name, original_entity.resource_weight_events) do |event| + event.attributes + .except('id', 'reference', 'reference_html') + .merge('issue_id' => new_entity.id) + end + end + + def copy_events(table_name, events_to_copy) + events_to_copy.find_in_batches do |batch| events = batch.map do |event| - event.attributes - .except('id', 'reference', 'reference_html') - .merge('issue_id' => new_entity.id) - end + yield(event) + end.compact - Gitlab::Database.bulk_insert(ResourceWeightEvent.table_name, events) + Gitlab::Database.bulk_insert(table_name, events) end end diff --git a/changelogs/unreleased/195888-import_to_find_group_objects_within_all_group_ancestors.yml b/changelogs/unreleased/195888-import_to_find_group_objects_within_all_group_ancestors.yml new file mode 100644 index 00000000000..d9c9986e202 --- /dev/null +++ b/changelogs/unreleased/195888-import_to_find_group_objects_within_all_group_ancestors.yml @@ -0,0 +1,5 @@ +--- +title: Search group-level objects among all ancestors during project import +merge_request: +author: +type: changed diff --git a/changelogs/unreleased/37745-optimize-pipelines-finder.yml b/changelogs/unreleased/37745-optimize-pipelines-finder.yml new file mode 100644 index 00000000000..f6ff6b363b0 --- /dev/null +++ b/changelogs/unreleased/37745-optimize-pipelines-finder.yml @@ -0,0 +1,5 @@ +--- +title: Fix query performance in PipelinesFinder +merge_request: 21092 +author: +type: performance diff --git a/changelogs/unreleased/ab-projects-api-remove-unneeded-indexes.yml b/changelogs/unreleased/ab-projects-api-remove-unneeded-indexes.yml new file mode 100644 index 00000000000..b86e77e67f4 --- /dev/null +++ b/changelogs/unreleased/ab-projects-api-remove-unneeded-indexes.yml @@ -0,0 +1,5 @@ +--- +title: Remove unneeded indexes on projects table +merge_request: 24086 +author: +type: performance diff --git a/danger/roulette/Dangerfile b/danger/roulette/Dangerfile index 173cf4e0ea2..f0e5c668cb8 100644 --- a/danger/roulette/Dangerfile +++ b/danger/roulette/Dangerfile @@ -16,6 +16,10 @@ To spread load more evenly across eligible reviewers, Danger has randomly picked a candidate for each review slot. Feel free to override this selection if you think someone else would be better-suited, or the chosen person is unavailable. +To read more on how to use the reviewer roulette, please take a look at the +[Engineering workflow](https://about.gitlab.com/handbook/engineering/workflow/#basics) +and [code review guidelines](https://docs.gitlab.com/ee/development/code_review.html). + Once you've decided who will review this merge request, mention them as you normally would! Danger does not (yet?) automatically notify them for you. diff --git a/db/migrate/20200130161817_drop_unneeded_indexes_for_projects_api_requests.rb b/db/migrate/20200130161817_drop_unneeded_indexes_for_projects_api_requests.rb new file mode 100644 index 00000000000..50b98ab9dba --- /dev/null +++ b/db/migrate/20200130161817_drop_unneeded_indexes_for_projects_api_requests.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class DropUnneededIndexesForProjectsApiRequests < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + + def up + indexes = %w( + index_projects_api_vis20_created_at_id_desc + index_projects_api_vis20_last_activity_at_id_desc + index_projects_api_vis20_updated_at_id_desc + index_projects_api_vis20_name_id_desc + index_projects_api_vis20_path_id_desc + ) + + indexes.each do |index| + remove_concurrent_index_by_name :projects, index + end + end + + def down + columns = %i(created_at last_activity_at updated_at name path) + + columns.each do |column| + add_concurrent_index :projects, [column, :id], where: 'visibility_level = 20', order: { id: :desc }, name: "index_projects_api_vis20_#{column}_id_desc" + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 98f127020de..4aadcc50856 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_01_29_035708) do +ActiveRecord::Schema.define(version: 2020_01_30_161817) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -3382,7 +3382,6 @@ ActiveRecord::Schema.define(version: 2020_01_29_035708) do t.index "lower((name)::text)", name: "index_projects_on_lower_name" t.index ["created_at", "id"], name: "index_projects_api_created_at_id_desc", order: { id: :desc } t.index ["created_at", "id"], name: "index_projects_api_vis20_created_at", where: "(visibility_level = 20)" - t.index ["created_at", "id"], name: "index_projects_api_vis20_created_at_id_desc", order: { id: :desc }, where: "(visibility_level = 20)" t.index ["created_at", "id"], name: "index_projects_on_created_at_and_id" t.index ["creator_id"], name: "index_projects_on_creator_id" t.index ["description"], name: "index_projects_on_description_trigram", opclass: :gin_trgm_ops, using: :gin @@ -3392,7 +3391,6 @@ ActiveRecord::Schema.define(version: 2020_01_29_035708) do t.index ["id"], name: "index_projects_on_mirror_and_mirror_trigger_builds_both_true", where: "((mirror IS TRUE) AND (mirror_trigger_builds IS TRUE))" t.index ["last_activity_at", "id"], name: "index_projects_api_last_activity_at_id_desc", order: { id: :desc } t.index ["last_activity_at", "id"], name: "index_projects_api_vis20_last_activity_at", where: "(visibility_level = 20)" - t.index ["last_activity_at", "id"], name: "index_projects_api_vis20_last_activity_at_id_desc", order: { id: :desc }, where: "(visibility_level = 20)" t.index ["last_activity_at", "id"], name: "index_projects_on_last_activity_at_and_id" t.index ["last_repository_check_at"], name: "index_projects_on_last_repository_check_at", where: "(last_repository_check_at IS NOT NULL)" t.index ["last_repository_check_failed"], name: "index_projects_on_last_repository_check_failed" @@ -3403,13 +3401,11 @@ ActiveRecord::Schema.define(version: 2020_01_29_035708) do t.index ["mirror_user_id"], name: "index_projects_on_mirror_user_id" t.index ["name", "id"], name: "index_projects_api_name_id_desc", order: { id: :desc } t.index ["name", "id"], name: "index_projects_api_vis20_name", where: "(visibility_level = 20)" - t.index ["name", "id"], name: "index_projects_api_vis20_name_id_desc", order: { id: :desc }, where: "(visibility_level = 20)" t.index ["name", "id"], name: "index_projects_on_name_and_id" t.index ["name"], name: "index_projects_on_name_trigram", opclass: :gin_trgm_ops, using: :gin t.index ["namespace_id"], name: "index_projects_on_namespace_id" t.index ["path", "id"], name: "index_projects_api_path_id_desc", order: { id: :desc } t.index ["path", "id"], name: "index_projects_api_vis20_path", where: "(visibility_level = 20)" - t.index ["path", "id"], name: "index_projects_api_vis20_path_id_desc", order: { id: :desc }, where: "(visibility_level = 20)" t.index ["path", "id"], name: "index_projects_on_path_and_id" t.index ["path"], name: "index_projects_on_path_trigram", opclass: :gin_trgm_ops, using: :gin t.index ["pending_delete"], name: "index_projects_on_pending_delete" @@ -3421,7 +3417,6 @@ ActiveRecord::Schema.define(version: 2020_01_29_035708) do t.index ["star_count"], name: "index_projects_on_star_count" t.index ["updated_at", "id"], name: "index_projects_api_updated_at_id_desc", order: { id: :desc } t.index ["updated_at", "id"], name: "index_projects_api_vis20_updated_at", where: "(visibility_level = 20)" - t.index ["updated_at", "id"], name: "index_projects_api_vis20_updated_at_id_desc", order: { id: :desc }, where: "(visibility_level = 20)" t.index ["updated_at", "id"], name: "index_projects_on_updated_at_and_id" end diff --git a/doc/development/contributing/style_guides.md b/doc/development/contributing/style_guides.md index f35757249fc..24c8de80e51 100644 --- a/doc/development/contributing/style_guides.md +++ b/doc/development/contributing/style_guides.md @@ -4,7 +4,9 @@ You're strongly advised to install [Overcommit](https://github.com/sds/overcommit) to automatically check for -static analysis offenses before committing locally: +static analysis offenses before committing locally. + +In your GitLab source directory run: ```shell cd tooling/overcommit && make && cd - diff --git a/doc/development/go_guide/index.md b/doc/development/go_guide/index.md index 59efc7be2f4..d9641bcfbab 100644 --- a/doc/development/go_guide/index.md +++ b/doc/development/go_guide/index.md @@ -52,9 +52,9 @@ Web servers can take advantages of middlewares like [Secure](https://github.com/ Many of our projects are too small to have full-time maintainers. That's why we have a shared pool of Go reviewers at GitLab. To find a reviewer, use the -[Engineering Projects](https://about.gitlab.com/handbook/engineering/projects/) -page in the handbook. "GitLab Community Edition (CE)" and "GitLab Community -Edition (EE)" both have a "Go" section with its list of reviewers. +["Go" section](https://about.gitlab.com/handbook/engineering/projects/#gitlab_reviewers_go) +of the "GitLab" project on the Engineering Projects +page in the handbook. To add yourself to this list, add the following to your profile in the [team.yml](https://gitlab.com/gitlab-com/www-gitlab-com/blob/master/data/team.yml) diff --git a/doc/fixtures/gitlab_tanuki.png b/doc/fixtures/gitlab_tanuki.png Binary files differdeleted file mode 100644 index 551dd6ce2ce..00000000000 --- a/doc/fixtures/gitlab_tanuki.png +++ /dev/null diff --git a/doc/user/markdown.md b/doc/user/markdown.md index 5bfbc6c1ec8..c83fb3260c8 100644 --- a/doc/user/markdown.md +++ b/doc/user/markdown.md @@ -896,6 +896,11 @@ Reference-style (hover to see title text): [logo]: img/markdown_logo.png "Title Text" ``` +<!-- +DO NOT change the name of markdown_logo.png. This is used for a test +in spec/controllers/help_controller_spec.rb. +--> + Inline-style (hover to see title text): ![alt text](img/markdown_logo.png "Title Text") diff --git a/lib/gitlab/import_export/group_project_object_builder.rb b/lib/gitlab/import_export/group_project_object_builder.rb index d6d780f165e..9e8f9d11393 100644 --- a/lib/gitlab/import_export/group_project_object_builder.rb +++ b/lib/gitlab/import_export/group_project_object_builder.rb @@ -50,7 +50,7 @@ module Gitlab def where_clause_base [].tap do |clauses| clauses << table[:project_id].eq(project.id) if project - clauses << table[:group_id].eq(group.id) if group + clauses << table[:group_id].in(group.self_and_ancestors_ids) if group end.reduce(:or) end @@ -60,7 +60,9 @@ module Gitlab end def prepare_attributes - attributes.except('group').tap do |atts| + attributes.dup.tap do |atts| + atts.delete('group') unless epic? + if label? atts['type'] = 'ProjectLabel' # Always create project labels elsif milestone? diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index 3fce296ef90..e010cac2f73 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -111,7 +111,7 @@ describe HelpController do it 'renders the raw file' do get :show, params: { - path: 'fixtures/gitlab_tanuki' + path: 'user/img/markdown_logo' }, format: :png expect(response).to be_successful diff --git a/spec/lib/gitlab/import_export/group_project_object_builder_spec.rb b/spec/lib/gitlab/import_export/group_project_object_builder_spec.rb index 355757654da..34049cbf570 100644 --- a/spec/lib/gitlab/import_export/group_project_object_builder_spec.rb +++ b/spec/lib/gitlab/import_export/group_project_object_builder_spec.rb @@ -3,13 +3,15 @@ require 'spec_helper' describe Gitlab::ImportExport::GroupProjectObjectBuilder do - let(:project) do + let!(:group) { create(:group, :private) } + let!(:subgroup) { create(:group, :private, parent: group) } + let!(:project) do create(:project, :repository, :builds_disabled, :issues_disabled, name: 'project', path: 'project', - group: create(:group)) + group: subgroup) end let(:lru_cache) { subject.send(:lru_cache) } @@ -75,6 +77,15 @@ describe Gitlab::ImportExport::GroupProjectObjectBuilder do 'group' => project.group)).to eq(group_label) end + it 'finds the existing group label in root ancestor' do + group_label = create(:group_label, name: 'group label', group: group) + + expect(described_class.build(Label, + 'title' => 'group label', + 'project' => project, + 'group' => group)).to eq(group_label) + end + it 'creates a new label' do label = described_class.build(Label, 'title' => 'group label', @@ -95,6 +106,15 @@ describe Gitlab::ImportExport::GroupProjectObjectBuilder do 'group' => project.group)).to eq(milestone) end + it 'finds the existing group milestone in root ancestor' do + milestone = create(:milestone, name: 'group milestone', group: group) + + expect(described_class.build(Milestone, + 'title' => 'group milestone', + 'project' => project, + 'group' => group)).to eq(milestone) + end + it 'creates a new milestone' do milestone = described_class.build(Milestone, 'title' => 'group milestone', |