diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-06 12:10:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-06 12:10:16 +0300 |
commit | ff490fb7dfd0f4fedbd45b9079fcfa13ade3144c (patch) | |
tree | ddd60efa57e53b4e278a928824e61258f4368f38 | |
parent | 8f5ebbe2c7488fd8285e528cc3c0b2b3fdd0d2e0 (diff) |
Add latest changes from gitlab-org/gitlab@master
-rw-r--r-- | app/assets/javascripts/diffs/components/app.vue | 8 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/store/actions.js | 10 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/store/getters.js | 4 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/store/modules/diff_state.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/store/mutation_types.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/store/mutations.js | 3 | ||||
-rw-r--r-- | lib/gitlab/database/load_balancing/load_balancer.rb | 36 | ||||
-rw-r--r-- | locale/gitlab.pot | 24 | ||||
-rw-r--r-- | spec/frontend/diffs/store/actions_spec.js | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb | 23 |
10 files changed, 91 insertions, 24 deletions
diff --git a/app/assets/javascripts/diffs/components/app.vue b/app/assets/javascripts/diffs/components/app.vue index 6d3d113f932..1860a45207f 100644 --- a/app/assets/javascripts/diffs/components/app.vue +++ b/app/assets/javascripts/diffs/components/app.vue @@ -172,7 +172,6 @@ export default { treeWidth, diffFilesLength: 0, virtualScrollCurrentIndex: -1, - disableVirtualScroller: false, }; }, computed: { @@ -414,6 +413,7 @@ export default { 'setShowTreeList', 'navigateToDiffFileIndex', 'setFileByFile', + 'disableVirtualScroller', ]), subscribeToEvents() { notesEventHub.$once('fetchDiffData', this.fetchData); @@ -522,11 +522,11 @@ export default { // To make sure the user is using the find function we need to wait for blur // and max 1000ms to be sure it the search box is filtered if (delta >= 0 && delta < 1000) { - this.disableVirtualScroller = true; + this.disableVirtualScroller(); if (window.gon?.features?.diffSearchingUsageData) { api.trackRedisHllUserEvent('i_code_review_user_searches_diff'); - api.trackRedisCounterEvent('user_searches_diffs'); + api.trackRedisCounterEvent('diff_searches'); } } } @@ -651,7 +651,7 @@ export default { <div v-if="isBatchLoading" class="loading"><gl-loading-icon size="lg" /></div> <template v-else-if="renderDiffFiles"> <dynamic-scroller - v-if="!disableVirtualScroller && isVirtualScrollingEnabled" + v-if="isVirtualScrollingEnabled" ref="virtualScroller" :items="diffs" :min-item-size="70" diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js index f8cc39fc238..d11e7dc838f 100644 --- a/app/assets/javascripts/diffs/store/actions.js +++ b/app/assets/javascripts/diffs/store/actions.js @@ -520,14 +520,14 @@ export const toggleActiveFileByHash = ({ commit }, hash) => { commit(types.VIEW_DIFF_FILE, hash); }; -export const scrollToFile = ({ state, commit }, path) => { +export const scrollToFile = ({ state, commit, getters }, path) => { if (!state.treeEntries[path]) return; const { fileHash } = state.treeEntries[path]; commit(types.VIEW_DIFF_FILE, fileHash); - if (window.gon?.features?.diffsVirtualScrolling) { + if (getters.isVirtualScrollingEnabled) { eventHub.$emit('scrollToFileHash', fileHash); setTimeout(() => { @@ -535,6 +535,10 @@ export const scrollToFile = ({ state, commit }, path) => { }); } else { document.location.hash = fileHash; + + setTimeout(() => { + handleLocationHash(); + }); } }; @@ -844,3 +848,5 @@ export function reviewFile({ commit, state }, { file, reviewed = true }) { setReviewsForMergeRequest(mrPath, reviews); commit(types.SET_MR_FILE_REVIEWS, reviews); } + +export const disableVirtualScroller = ({ commit }) => commit(types.DISABLE_VIRTUAL_SCROLLING); diff --git a/app/assets/javascripts/diffs/store/getters.js b/app/assets/javascripts/diffs/store/getters.js index 18af8151dc4..18bd8e5f1d8 100644 --- a/app/assets/javascripts/diffs/store/getters.js +++ b/app/assets/javascripts/diffs/store/getters.js @@ -177,6 +177,10 @@ export function suggestionCommitMessage(state, _, rootState) { export const isVirtualScrollingEnabled = (state) => { const vSrollerCookie = Cookies.get('diffs_virtual_scrolling'); + if (state.disableVirtualScroller) { + return false; + } + if (vSrollerCookie) { return vSrollerCookie === 'true'; } diff --git a/app/assets/javascripts/diffs/store/modules/diff_state.js b/app/assets/javascripts/diffs/store/modules/diff_state.js index 348dd452698..d76361513d4 100644 --- a/app/assets/javascripts/diffs/store/modules/diff_state.js +++ b/app/assets/javascripts/diffs/store/modules/diff_state.js @@ -43,4 +43,5 @@ export default () => ({ defaultSuggestionCommitMessage: '', mrReviews: {}, latestDiff: true, + disableVirtualScroller: false, }); diff --git a/app/assets/javascripts/diffs/store/mutation_types.js b/app/assets/javascripts/diffs/store/mutation_types.js index 4641731c4b6..2c370221f40 100644 --- a/app/assets/javascripts/diffs/store/mutation_types.js +++ b/app/assets/javascripts/diffs/store/mutation_types.js @@ -47,3 +47,4 @@ export const SET_DIFF_FILE_VIEWER = 'SET_DIFF_FILE_VIEWER'; export const SET_SHOW_SUGGEST_POPOVER = 'SET_SHOW_SUGGEST_POPOVER'; export const TOGGLE_LINE_DISCUSSIONS = 'TOGGLE_LINE_DISCUSSIONS'; +export const DISABLE_VIRTUAL_SCROLLING = 'DISABLE_VIRTUAL_SCROLLING'; diff --git a/app/assets/javascripts/diffs/store/mutations.js b/app/assets/javascripts/diffs/store/mutations.js index 9ff9a02d444..1aa83453bf7 100644 --- a/app/assets/javascripts/diffs/store/mutations.js +++ b/app/assets/javascripts/diffs/store/mutations.js @@ -362,4 +362,7 @@ export default { [types.SET_MR_FILE_REVIEWS](state, newReviews) { state.mrReviews = newReviews; }, + [types.DISABLE_VIRTUAL_SCROLLING](state) { + state.disableVirtualScroller = true; + }, }; diff --git a/lib/gitlab/database/load_balancing/load_balancer.rb b/lib/gitlab/database/load_balancing/load_balancer.rb index 4f009df6331..f5c68a26e76 100644 --- a/lib/gitlab/database/load_balancing/load_balancer.rb +++ b/lib/gitlab/database/load_balancing/load_balancer.rb @@ -7,19 +7,17 @@ module Gitlab # # Each host in the load balancer uses the same credentials as the primary # database. - # - # This class *requires* that `ActiveRecord::Base.retrieve_connection` - # always returns a connection to the primary. class LoadBalancer CACHE_KEY = :gitlab_load_balancer_host attr_reader :host_list # hosts - The hostnames/addresses of the additional databases. - def initialize(hosts = []) + def initialize(hosts = [], model = ActiveRecord::Base) @host_list = HostList.new(hosts.map { |addr| Host.new(addr, self) }) @connection_db_roles = {}.compare_by_identity @connection_db_roles_count = {}.compare_by_identity + @model = model end # Yields a connection that can be used for reads. @@ -94,7 +92,7 @@ module Gitlab # Instead of immediately grinding to a halt we'll retry the operation # a few times. retry_with_backoff do - connection = ActiveRecord::Base.retrieve_connection + connection = pool.connection track_connection_role(connection, ROLE_PRIMARY) yield connection @@ -109,7 +107,7 @@ module Gitlab def db_role_for_connection(connection) return @connection_db_roles[connection] if @connection_db_roles[connection] return ROLE_REPLICA if @host_list.manage_pool?(connection.pool) - return ROLE_PRIMARY if connection.pool == ActiveRecord::Base.connection_pool + return ROLE_PRIMARY if connection.pool == pool end # Returns a host to use for queries. @@ -117,21 +115,21 @@ module Gitlab # Hosts are scoped per thread so that multiple threads don't # accidentally re-use the same host + connection. def host - RequestStore[CACHE_KEY] ||= @host_list.next + request_cache[CACHE_KEY] ||= @host_list.next end # Releases the host and connection for the current thread. def release_host - if host = RequestStore[CACHE_KEY] + if host = request_cache[CACHE_KEY] host.disable_query_cache! host.release_connection end - RequestStore.delete(CACHE_KEY) + request_cache.delete(CACHE_KEY) end def release_primary_connection - ActiveRecord::Base.connection_pool.release_connection + pool.release_connection end # Returns the transaction write location of the primary. @@ -152,7 +150,7 @@ module Gitlab return false unless host - RequestStore[CACHE_KEY] = host + request_cache[CACHE_KEY] = host true end @@ -209,6 +207,17 @@ module Gitlab private + # ActiveRecord::ConnectionAdapters::ConnectionHandler handles fetching, + # and caching for connections pools for each "connection", so we + # leverage that. + def pool + ActiveRecord::Base.connection_handler.retrieve_connection_pool( + @model.connection_specification_name, + role: ActiveRecord::Base.writing_role, + shard: ActiveRecord::Base.default_shard + ) + end + def ensure_caching! host.enable_query_cache! unless host.query_cache_enabled end @@ -228,6 +237,11 @@ module Gitlab @connection_db_roles_count.delete(connection) end end + + def request_cache + base = RequestStore[:gitlab_load_balancer] ||= {} + base[pool] ||= {} + end end end end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 3f985b32a1e..d8f0d38ee17 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -9229,6 +9229,9 @@ msgstr "" msgid "Could not draw the lines for job relationships" msgstr "" +msgid "Could not fetch policy because existing policy YAML is invalid" +msgstr "" + msgid "Could not find design." msgstr "" @@ -17987,6 +17990,9 @@ msgstr "" msgid "Invalid pod_name" msgstr "" +msgid "Invalid policy type" +msgstr "" + msgid "Invalid query" msgstr "" @@ -24906,6 +24912,9 @@ msgstr "" msgid "Policies" msgstr "" +msgid "Policy management project does have any policies in %{policy_path}" +msgstr "" + msgid "Policy project doesn't exist" msgstr "" @@ -25671,6 +25680,9 @@ msgstr "" msgid "Project does not exist or you don't have permission to perform this action" msgstr "" +msgid "Project does not have a policy configuration" +msgstr "" + msgid "Project export could not be deleted." msgstr "" @@ -29430,6 +29442,9 @@ msgstr "" msgid "SecurityPolicies|Description" msgstr "" +msgid "SecurityPolicies|Edit policy" +msgstr "" + msgid "SecurityPolicies|Enforcement status" msgstr "" @@ -29442,6 +29457,9 @@ msgstr "" msgid "SecurityPolicies|Network" msgstr "" +msgid "SecurityPolicies|Policies" +msgstr "" + msgid "SecurityPolicies|Policy type" msgstr "" @@ -30372,6 +30390,9 @@ msgstr "" msgid "Settings" msgstr "" +msgid "Settings|Unable to load the merge request options settings. Try reloading the page." +msgstr "" + msgid "Setup" msgstr "" @@ -40064,6 +40085,9 @@ msgstr "" msgid "type must be Debian" msgstr "" +msgid "type parameter is missing and is required" +msgstr "" + msgid "unicode domains should use IDNA encoding" msgstr "" diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js index 4681b4f9d45..6d005b868a9 100644 --- a/spec/frontend/diffs/store/actions_spec.js +++ b/spec/frontend/diffs/store/actions_spec.js @@ -874,6 +874,7 @@ describe('DiffsStoreActions', () => { describe('scrollToFile', () => { let commit; + const getters = { isVirtualScrollingEnabled: false }; beforeEach(() => { commit = jest.fn(); @@ -888,7 +889,7 @@ describe('DiffsStoreActions', () => { }, }; - scrollToFile({ state, commit }, 'path'); + scrollToFile({ state, commit, getters }, 'path'); expect(document.location.hash).toBe('#test'); }); @@ -902,7 +903,7 @@ describe('DiffsStoreActions', () => { }, }; - scrollToFile({ state, commit }, 'path'); + scrollToFile({ state, commit, getters }, 'path'); expect(commit).toHaveBeenCalledWith(types.VIEW_DIFF_FILE, 'test'); }); diff --git a/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb b/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb index 2c3858e68bf..01a17cb2805 100644 --- a/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb +++ b/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb @@ -7,6 +7,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do let(:conflict_error) { Class.new(RuntimeError) } let(:lb) { described_class.new(%w(localhost localhost)) } + let(:request_cache) { lb.send(:request_cache) } before do allow(Gitlab::Database.main).to receive(:create_connection_pool) @@ -123,8 +124,9 @@ RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do describe '#read_write' do it 'yields a connection for a write' do - expect { |b| lb.read_write(&b) } - .to yield_with_args(ActiveRecord::Base.retrieve_connection) + connection = ActiveRecord::Base.connection_pool.connection + + expect { |b| lb.read_write(&b) }.to yield_with_args(connection) end it 'uses a retry with exponential backoffs' do @@ -260,13 +262,24 @@ RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do end it 'stores the host in a thread-local variable' do - RequestStore.delete(described_class::CACHE_KEY) + request_cache.delete(described_class::CACHE_KEY) expect(lb.host_list).to receive(:next).once.and_call_original lb.host lb.host end + + it 'does not create conflicts with other load balancers when caching hosts' do + lb1 = described_class.new(%w(localhost localhost), ActiveRecord::Base) + lb2 = described_class.new(%w(localhost localhost), Ci::CiDatabaseRecord) + + host1 = lb1.host + host2 = lb2.host + + expect(lb1.send(:request_cache)[described_class::CACHE_KEY]).to eq(host1) + expect(lb2.send(:request_cache)[described_class::CACHE_KEY]).to eq(host2) + end end describe '#release_host' do @@ -277,7 +290,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do lb.release_host - expect(RequestStore[described_class::CACHE_KEY]).to be_nil + expect(request_cache[described_class::CACHE_KEY]).to be_nil end end @@ -415,7 +428,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do describe '#select_up_to_date_host' do let(:location) { 'AB/12345'} let(:hosts) { lb.host_list.hosts } - let(:set_host) { RequestStore[described_class::CACHE_KEY] } + let(:set_host) { request_cache[described_class::CACHE_KEY] } subject { lb.select_up_to_date_host(location) } |