diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-18 06:13:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-18 06:13:28 +0300 |
commit | 581a24da7e744ad5e7af9519e3b1c05344ead93c (patch) | |
tree | c44e911b8604bb09e46a107dc577a3687df4aeef | |
parent | e1d036885e2f5720e847d9009f60c5d7baad0015 (diff) |
Add latest changes from gitlab-org/gitlab@master
8 files changed, 150 insertions, 3 deletions
diff --git a/app/assets/javascripts/boards/components/issue_board_filtered_search.vue b/app/assets/javascripts/boards/components/issue_board_filtered_search.vue index 877f9fdf41d..7fc87f9f672 100644 --- a/app/assets/javascripts/boards/components/issue_board_filtered_search.vue +++ b/app/assets/javascripts/boards/components/issue_board_filtered_search.vue @@ -2,6 +2,7 @@ import { GlFilteredSearchToken } from '@gitlab/ui'; import fuzzaldrinPlus from 'fuzzaldrin-plus'; import { mapActions } from 'vuex'; +import { orderBy } from 'lodash'; import BoardFilteredSearch from 'ee_else_ce/boards/components/board_filtered_search.vue'; import { BoardType } from '~/boards/constants'; import axios from '~/lib/utils/axios_utils'; @@ -79,7 +80,7 @@ export default { this.boardType, ); - return [ + const tokens = [ { icon: 'user', title: assignee, @@ -189,6 +190,8 @@ export default { }, }, ]; + + return orderBy(tokens, ['title']); }, tokens() { return this.tokensCE; diff --git a/app/assets/javascripts/issues_list/components/issues_list_app.vue b/app/assets/javascripts/issues_list/components/issues_list_app.vue index af724bfac2d..6ced1080b71 100644 --- a/app/assets/javascripts/issues_list/components/issues_list_app.vue +++ b/app/assets/javascripts/issues_list/components/issues_list_app.vue @@ -10,6 +10,7 @@ import { } from '@gitlab/ui'; import * as Sentry from '@sentry/browser'; import fuzzaldrinPlus from 'fuzzaldrin-plus'; +import { orderBy } from 'lodash'; import getIssuesQuery from 'ee_else_ce/issues_list/queries/get_issues.query.graphql'; import getIssuesCountsQuery from 'ee_else_ce/issues_list/queries/get_issues_counts.query.graphql'; import IssueCardTimeInfo from 'ee_else_ce/issues_list/components/issue_card_time_info.vue'; @@ -405,7 +406,7 @@ export default { tokens.sort((a, b) => a.title.localeCompare(b.title)); - return tokens; + return orderBy(tokens, ['title']); }, showPaginationControls() { return this.issues.length > 0 && (this.pageInfo.hasNextPage || this.pageInfo.hasPreviousPage); diff --git a/db/post_migrate/20211215090620_schedule_update_timelogs_null_spent_at.rb b/db/post_migrate/20211215090620_schedule_update_timelogs_null_spent_at.rb new file mode 100644 index 00000000000..5876d3f8a9a --- /dev/null +++ b/db/post_migrate/20211215090620_schedule_update_timelogs_null_spent_at.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class ScheduleUpdateTimelogsNullSpentAt < Gitlab::Database::Migration[1.0] + DOWNTIME = false + BATCH_SIZE = 5_000 + DELAY_INTERVAL = 2.minutes + MIGRATION = 'UpdateTimelogsNullSpentAt' + + disable_ddl_transaction! + + def up + queue_background_migration_jobs_by_range_at_intervals( + define_batchable_model('timelogs').where(spent_at: nil), + MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + end + + def down + # no-op + end +end diff --git a/db/schema_migrations/20211215090620 b/db/schema_migrations/20211215090620 new file mode 100644 index 00000000000..9393ffee22e --- /dev/null +++ b/db/schema_migrations/20211215090620 @@ -0,0 +1 @@ +43ae6290e11e3944b23ce2865b5c466a29c9ba3cfd2e0b58bd834568414b5bf2
\ No newline at end of file diff --git a/lib/gitlab/background_migration/update_timelogs_null_spent_at.rb b/lib/gitlab/background_migration/update_timelogs_null_spent_at.rb new file mode 100644 index 00000000000..c95ef9f5515 --- /dev/null +++ b/lib/gitlab/background_migration/update_timelogs_null_spent_at.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # Class to populate spent_at for timelogs + class UpdateTimelogsNullSpentAt + include Gitlab::Database::DynamicModelHelpers + + BATCH_SIZE = 100 + + def perform(start_id, stop_id) + define_batchable_model('timelogs').where(spent_at: nil, id: start_id..stop_id).each_batch(of: 100) do |subbatch| + batch_start, batch_end = subbatch.pluck('min(id), max(id)').first + + update_timelogs(batch_start, batch_end) + end + end + + def update_timelogs(batch_start, batch_stop) + execute(<<~SQL) + UPDATE timelogs + SET spent_at = created_at + WHERE spent_at IS NULL + AND timelogs.id BETWEEN #{batch_start} AND #{batch_stop}; + SQL + end + + def execute(sql) + @connection ||= ::ActiveRecord::Base.connection + @connection.execute(sql) + end + end + end +end diff --git a/spec/frontend/boards/components/issue_board_filtered_search_spec.js b/spec/frontend/boards/components/issue_board_filtered_search_spec.js index af2ad90396f..76e8b84d8ef 100644 --- a/spec/frontend/boards/components/issue_board_filtered_search_spec.js +++ b/spec/frontend/boards/components/issue_board_filtered_search_spec.js @@ -1,3 +1,4 @@ +import { orderBy } from 'lodash'; import { shallowMount } from '@vue/test-utils'; import BoardFilteredSearch from 'ee_else_ce/boards/components/board_filtered_search.vue'; import IssueBoardFilteredSpec from '~/boards/components/issue_board_filtered_search.vue'; @@ -62,7 +63,7 @@ describe('IssueBoardFilter', () => { isSignedIn, ); - expect(findBoardsFilteredSearch().props('tokens')).toEqual(tokens); + expect(findBoardsFilteredSearch().props('tokens')).toEqual(orderBy(tokens, ['title'])); }, ); }); diff --git a/spec/lib/gitlab/background_migration/update_timelogs_null_spent_at_spec.rb b/spec/lib/gitlab/background_migration/update_timelogs_null_spent_at_spec.rb new file mode 100644 index 00000000000..982e3319063 --- /dev/null +++ b/spec/lib/gitlab/background_migration/update_timelogs_null_spent_at_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::UpdateTimelogsNullSpentAt, schema: 20211215090620 do + let_it_be(:previous_time) { 10.days.ago } + let_it_be(:namespace) { table(:namespaces).create!(name: 'namespace', path: 'namespace') } + let_it_be(:project) { table(:projects).create!(namespace_id: namespace.id) } + let_it_be(:issue) { table(:issues).create!(project_id: project.id) } + let_it_be(:merge_request) { table(:merge_requests).create!(target_project_id: project.id, source_branch: 'master', target_branch: 'feature') } + let_it_be(:timelog1) { create_timelog!(issue_id: issue.id) } + let_it_be(:timelog2) { create_timelog!(merge_request_id: merge_request.id) } + let_it_be(:timelog3) { create_timelog!(issue_id: issue.id, spent_at: previous_time) } + let_it_be(:timelog4) { create_timelog!(merge_request_id: merge_request.id, spent_at: previous_time) } + + subject(:background_migration) { described_class.new } + + before_all do + table(:timelogs).where.not(id: [timelog3.id, timelog4.id]).update_all(spent_at: nil) + end + + describe '#perform' do + it 'sets correct spent_at' do + background_migration.perform(timelog1.id, timelog4.id) + + expect(timelog1.reload.spent_at).to be_like_time(timelog1.created_at) + expect(timelog2.reload.spent_at).to be_like_time(timelog2.created_at) + expect(timelog3.reload.spent_at).to be_like_time(previous_time) + expect(timelog4.reload.spent_at).to be_like_time(previous_time) + expect(timelog3.reload.spent_at).not_to be_like_time(timelog3.created_at) + expect(timelog4.reload.spent_at).not_to be_like_time(timelog4.created_at) + end + end + + private + + def create_timelog!(**args) + table(:timelogs).create!(**args, time_spent: 1) + end +end diff --git a/spec/migrations/schedule_update_timelogs_null_spent_at_spec.rb b/spec/migrations/schedule_update_timelogs_null_spent_at_spec.rb new file mode 100644 index 00000000000..a81059518e6 --- /dev/null +++ b/spec/migrations/schedule_update_timelogs_null_spent_at_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe ScheduleUpdateTimelogsNullSpentAt do + let_it_be(:namespace) { table(:namespaces).create!(name: 'namespace', path: 'namespace') } + let_it_be(:project) { table(:projects).create!(namespace_id: namespace.id) } + let_it_be(:issue) { table(:issues).create!(project_id: project.id) } + let_it_be(:merge_request) { table(:merge_requests).create!(target_project_id: project.id, source_branch: 'master', target_branch: 'feature') } + let_it_be(:timelog1) { create_timelog!(merge_request_id: merge_request.id) } + let_it_be(:timelog2) { create_timelog!(merge_request_id: merge_request.id) } + let_it_be(:timelog3) { create_timelog!(merge_request_id: merge_request.id) } + let_it_be(:timelog4) { create_timelog!(issue_id: issue.id) } + let_it_be(:timelog5) { create_timelog!(issue_id: issue.id) } + + before_all do + table(:timelogs).where.not(id: timelog3.id).update_all(spent_at: nil) + end + + it 'correctly schedules background migrations' do + stub_const("#{described_class}::BATCH_SIZE", 2) + + Sidekiq::Testing.fake! do + freeze_time do + migrate! + + expect(described_class::MIGRATION) + .to be_scheduled_delayed_migration(2.minutes, timelog1.id, timelog2.id) + + expect(described_class::MIGRATION) + .to be_scheduled_delayed_migration(4.minutes, timelog4.id, timelog5.id) + + expect(BackgroundMigrationWorker.jobs.size).to eq(2) + end + end + end + + private + + def create_timelog!(**args) + table(:timelogs).create!(**args, time_spent: 1) + end +end |