diff options
9 files changed, 91 insertions, 10 deletions
diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION index 0d089c449eb..b9588bf08ad 100644 --- a/GITALY_SERVER_VERSION +++ b/GITALY_SERVER_VERSION @@ -1 +1 @@ -65bddca7ed089abdc7869c0f500825f29bd5a89f +56aa9a2196f0003bc011e4152bb093b8d32be83d diff --git a/app/assets/javascripts/ide/components/merge_requests/item.vue b/app/assets/javascripts/ide/components/merge_requests/item.vue index 639937481f3..2d9f74a06ee 100644 --- a/app/assets/javascripts/ide/components/merge_requests/item.vue +++ b/app/assets/javascripts/ide/components/merge_requests/item.vue @@ -41,7 +41,7 @@ export default { <template> <a :href="mergeRequestHref" class="btn-link d-flex align-items-center"> <span class="d-flex gl-mr-3 ide-search-list-current-icon"> - <gl-icon v-if="isActive" :size="18" name="mobile-issue-close" use-deprecated-sizes /> + <gl-icon v-if="isActive" :size="16" name="mobile-issue-close" /> </span> <span> <strong> {{ item.title }} </strong> diff --git a/app/assets/javascripts/issue_show/components/incidents/graphql/queries/get_alert.graphql b/app/assets/javascripts/issue_show/components/incidents/graphql/queries/get_alert.graphql index bb637dea033..938b90b3f7c 100644 --- a/app/assets/javascripts/issue_show/components/incidents/graphql/queries/get_alert.graphql +++ b/app/assets/javascripts/issue_show/components/incidents/graphql/queries/get_alert.graphql @@ -1,6 +1,7 @@ query getAlert($iid: String!, $fullPath: ID!) { project(fullPath: $fullPath) { issue(iid: $iid) { + id alertManagementAlert { iid title diff --git a/app/assets/javascripts/repository/components/table/row.vue b/app/assets/javascripts/repository/components/table/row.vue index 62f863db871..82c18d13a6a 100644 --- a/app/assets/javascripts/repository/components/table/row.vue +++ b/app/assets/javascripts/repository/components/table/row.vue @@ -186,6 +186,8 @@ export default { :is="linkComponent" ref="link" v-gl-hover-load="handlePreload" + v-gl-tooltip:tooltip-container + :title="fullPath" :to="routerLinkTo" :href="url" :class="{ diff --git a/doc/development/migration_style_guide.md b/doc/development/migration_style_guide.md index 009ead8ba16..7dd5dd74f0b 100644 --- a/doc/development/migration_style_guide.md +++ b/doc/development/migration_style_guide.md @@ -943,6 +943,41 @@ derived from the class name or namespace. Be aware of the limitations [when using models in migrations](#using-models-in-migrations-discouraged). +### Modifying existing data + +In most circumstances, prefer migrating data in **batches** when modifying data in the database. + +We introduced a new helper [each_batch_range](https://gitlab.com/gitlab-org/gitlab/-/blob/cd3e0a5cddcb464cb9b8c6e3275839cf57dfa6e2/lib/gitlab/database/dynamic_model_helpers.rb#L28-32) which facilitates the process of iterating over a collection in a performant way. The default size of the batch is defined in the `BATCH_SIZE` constant. + +See the following example to get an idea. + +**Purging data in batch:** + +```ruby +include ::Gitlab::Database::DynamicModelHelpers + +disable_ddl_transaction! + +def up + each_batch_range('ci_pending_builds', scope: ->(table) { table.ref_protected }, of: BATCH_SIZE) do |min, max| + execute <<~SQL + DELETE FROM ci_pending_builds + USING ci_builds + WHERE ci_builds.id = ci_pending_builds.build_id + AND ci_builds.status != 'pending' + AND ci_builds.type = 'Ci::Build' + AND ci_pending_builds.id BETWEEN #{min} AND #{max} + SQL + end +end +``` + +- The first argument is the table being modified: `'ci_pending_builds'`. +- The second argument calls a lambda which fetches the relevant dataset selected (the default is set to `.all`): `scope: ->(table) { table.ref_protected }`. +- The third argument is the batch size (the default is set in the `BATCH_SIZE` constant): `of: BATCH_SIZE`. + +Here is an [example MR](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62195) illustrating how to use our new helper. + ### Renaming reserved paths When a new route for projects is introduced, it could conflict with any diff --git a/lib/gitlab/database/dynamic_model_helpers.rb b/lib/gitlab/database/dynamic_model_helpers.rb index 7439591be99..220062f1bc6 100644 --- a/lib/gitlab/database/dynamic_model_helpers.rb +++ b/lib/gitlab/database/dynamic_model_helpers.rb @@ -3,6 +3,8 @@ module Gitlab module Database module DynamicModelHelpers + BATCH_SIZE = 1_000 + def define_batchable_model(table_name) Class.new(ActiveRecord::Base) do include EachBatch @@ -12,7 +14,7 @@ module Gitlab end end - def each_batch(table_name, scope: ->(table) { table.all }, of: 1000) + def each_batch(table_name, scope: ->(table) { table.all }, of: BATCH_SIZE) if transaction_open? raise <<~MSG.squish each_batch should not run inside a transaction, you can disable @@ -25,7 +27,7 @@ module Gitlab .each_batch(of: of) { |batch| yield batch } end - def each_batch_range(table_name, scope: ->(table) { table.all }, of: 1000) + def each_batch_range(table_name, scope: ->(table) { table.all }, of: BATCH_SIZE) each_batch(table_name, scope: scope, of: of) do |batch| yield batch.pluck('MIN(id), MAX(id)').first end diff --git a/rubocop/rubocop-migrations.yml b/rubocop/rubocop-migrations.yml index c8f50016710..979b0fa2936 100644 --- a/rubocop/rubocop-migrations.yml +++ b/rubocop/rubocop-migrations.yml @@ -42,6 +42,7 @@ Migration/UpdateLargeTable: - :user_details - :vulnerability_occurrences - :web_hook_logs + - :vulnerabilities DeniedMethods: - :change_column_type_concurrently - :rename_column_concurrently diff --git a/spec/features/issues/incident_issue_spec.rb b/spec/features/issues/incident_issue_spec.rb index d004ee85dd8..3033a138551 100644 --- a/spec/features/issues/incident_issue_spec.rb +++ b/spec/features/issues/incident_issue_spec.rb @@ -3,20 +3,57 @@ require 'spec_helper' RSpec.describe 'Incident Detail', :js do + let_it_be(:project) { create(:project, :public) } + let_it_be(:payload) do + { + 'title' => 'Alert title', + 'start_time' => '2020-04-27T10:10:22.265949279Z', + 'custom' => { + 'alert' => { + 'fields' => %w[one two] + } + }, + 'yet' => { + 'another' => 73 + } + } + end + + let_it_be(:user) { create(:user) } + let_it_be(:started_at) { Time.now.rfc3339 } + let_it_be(:alert) { create(:alert_management_alert, project: project, payload: payload, started_at: started_at) } + let_it_be(:incident) { create(:incident, project: project, description: 'hello', alert_management_alert: alert) } + context 'when user displays the incident' do - it 'shows the incident tabs' do - project = create(:project, :public) - incident = create(:incident, project: project, description: 'hello') + before do + project.add_developer(user) + sign_in(user) visit project_issue_path(project, incident) wait_for_requests + end + it 'shows incident and alert data' do page.within('.issuable-details') do incident_tabs = find('[data-testid="incident-tabs"]') - expect(find('h2')).to have_content(incident.title) - expect(incident_tabs).to have_content('Summary') - expect(incident_tabs).to have_content(incident.description) + aggregate_failures 'shows title and Summary tab' do + expect(find('h2')).to have_content(incident.title) + expect(incident_tabs).to have_content('Summary') + expect(incident_tabs).to have_content(incident.description) + end + + aggregate_failures 'shows the incident highlight bar' do + expect(incident_tabs).to have_content('Alert events: 1') + expect(incident_tabs).to have_content('Original alert: #1') + end + + aggregate_failures 'shows the Alert details tab' do + click_link 'Alert details' + + expect(incident_tabs).to have_content('"title": "Alert title"') + expect(incident_tabs).to have_content('"yet.another": 73') + end end end end diff --git a/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap b/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap index ac60fc4917d..6f461f4c69b 100644 --- a/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap +++ b/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap @@ -11,6 +11,7 @@ exports[`Repository table row component renders a symlink table row 1`] = ` class="tree-item-link str-truncated" data-qa-selector="file_name_link" href="https://test.com" + title="test" > <file-icon-stub class="mr-1 position-relative text-secondary" @@ -64,6 +65,7 @@ exports[`Repository table row component renders table row 1`] = ` class="tree-item-link str-truncated" data-qa-selector="file_name_link" href="https://test.com" + title="test" > <file-icon-stub class="mr-1 position-relative text-secondary" @@ -117,6 +119,7 @@ exports[`Repository table row component renders table row for path with special class="tree-item-link str-truncated" data-qa-selector="file_name_link" href="https://test.com" + title="test" > <file-icon-stub class="mr-1 position-relative text-secondary" |