diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 9 | ||||
-rw-r--r-- | lib/api/releases.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/discussions_diff/file_collection.rb | 29 | ||||
-rw-r--r-- | lib/gitlab/usage_data.rb | 49 |
4 files changed, 57 insertions, 34 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 53774d4db1a..4018ce900e1 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1044,7 +1044,12 @@ module API expose :job_events # Expose serialized properties expose :properties do |service, options| - service.properties.slice(*service.api_field_names) + # TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab-ce/issues/63084 + if service.data_fields_present? + service.data_fields.as_json.slice(*service.api_field_names) + else + service.properties.slice(*service.api_field_names) + end end end @@ -1280,7 +1285,7 @@ module API expose :author, using: Entities::UserBasic, if: -> (release, _) { release.author.present? } expose :commit, using: Entities::Commit, if: lambda { |_, _| can_download_code? } expose :upcoming_release?, as: :upcoming_release - expose :milestone, using: Entities::Milestone, if: -> (release, _) { release.milestone.present? } + expose :milestones, using: Entities::Milestone, if: -> (release, _) { release.milestones.present? } expose :assets do expose :assets_count, as: :count do |release, _| diff --git a/lib/api/releases.rb b/lib/api/releases.rb index 5a31581c4da..4238529142c 100644 --- a/lib/api/releases.rb +++ b/lib/api/releases.rb @@ -54,7 +54,7 @@ module API requires :url, type: String end end - optional :milestone, type: String, desc: 'The title of the related milestone' + optional :milestones, type: Array, desc: 'The titles of the related milestones', default: [] optional :released_at, type: DateTime, desc: 'The date when the release will be/was ready. Defaults to the current time.' end post ':id/releases' do @@ -80,7 +80,7 @@ module API optional :name, type: String, desc: 'The name of the release' optional :description, type: String, desc: 'Release notes with markdown support' optional :released_at, type: DateTime, desc: 'The date when the release will be/was ready.' - optional :milestone, type: String, desc: 'The title of the related milestone' + optional :milestones, type: Array, desc: 'The titles of the related milestones' end put ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do authorize_update_release! diff --git a/lib/gitlab/discussions_diff/file_collection.rb b/lib/gitlab/discussions_diff/file_collection.rb index 4ab7314f509..6692dd76438 100644 --- a/lib/gitlab/discussions_diff/file_collection.rb +++ b/lib/gitlab/discussions_diff/file_collection.rb @@ -4,11 +4,16 @@ module Gitlab module DiscussionsDiff class FileCollection include Gitlab::Utils::StrongMemoize + include Enumerable def initialize(collection) @collection = collection end + def each(&block) + @collection.each(&block) + end + # Returns a Gitlab::Diff::File with the given ID (`unique_identifier` in # Gitlab::Diff::File). def find_by_id(id) @@ -16,20 +21,12 @@ module Gitlab end # Writes cache and preloads highlighted diff lines for - # object IDs, in @collection. - # - # highlightable_ids - Diff file `Array` responding to ID. The ID will be used - # to generate the cache key. + # highlightable object IDs, in @collection. # # - Highlight cache is written just for uncached diff files # - The cache content is not updated (there's no need to do so) - def load_highlight(highlightable_ids) - preload_highlighted_lines(highlightable_ids) - end - - private - - def preload_highlighted_lines(ids) + def load_highlight + ids = highlightable_collection_ids cached_content = read_cache(ids) uncached_ids = ids.select.each_with_index { |_, i| cached_content[i].nil? } @@ -46,6 +43,12 @@ module Gitlab end end + private + + def highlightable_collection_ids + each.with_object([]) { |file, memo| memo << file.id unless file.resolved_at } + end + def read_cache(ids) HighlightCache.read_multiple(ids) end @@ -57,9 +60,7 @@ module Gitlab end def diff_files - strong_memoize(:diff_files) do - @collection.map(&:raw_diff_file) - end + strong_memoize(:diff_files) { map(&:raw_diff_file) } end # Processes the diff lines highlighting for diff files matching the given diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index 5cd54c302fc..c6c2876033d 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -3,6 +3,7 @@ module Gitlab class UsageData APPROXIMATE_COUNT_MODELS = [Label, MergeRequest, Note, Todo].freeze + BATCH_SIZE = 100 class << self def data(force_refresh: false) @@ -13,10 +14,10 @@ module Gitlab def uncached_data license_usage_data.merge(system_usage_data) - .merge(features_usage_data) - .merge(components_usage_data) - .merge(cycle_analytics_usage_data) - .merge(usage_counters) + .merge(features_usage_data) + .merge(components_usage_data) + .merge(cycle_analytics_usage_data) + .merge(usage_counters) end def to_json(force_refresh: false) @@ -96,9 +97,8 @@ module Gitlab todos: count(Todo), uploads: count(Upload), web_hooks: count(WebHook) - } - .merge(services_usage) - .merge(approximate_counts) + }.merge(services_usage) + .merge(approximate_counts) }.tap do |data| data[:counts][:user_preferences] = user_preferences_usage end @@ -173,17 +173,34 @@ module Gitlab def jira_usage # Jira Cloud does not support custom domains as per https://jira.atlassian.com/browse/CLOUD-6999 # so we can just check for subdomains of atlassian.net - services = count( - Service.unscoped.where(type: :JiraService, active: true) - .group("CASE WHEN properties LIKE '%.atlassian.net%' THEN 'cloud' ELSE 'server' END"), - fallback: Hash.new(-1) - ) - { - projects_jira_server_active: services['server'] || 0, - projects_jira_cloud_active: services['cloud'] || 0, - projects_jira_active: services['server'] == -1 ? -1 : services.values.sum + results = { + projects_jira_server_active: 0, + projects_jira_cloud_active: 0, + projects_jira_active: -1 } + + Service.unscoped + .where(type: :JiraService, active: true) + .includes(:jira_tracker_data) + .find_in_batches(batch_size: BATCH_SIZE) do |services| + + counts = services.group_by do |service| + # TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab-ce/issues/63084 + service_url = service.data_fields&.url || (service.properties && service.properties['url']) + service_url&.include?('.atlassian.net') ? :cloud : :server + end + + results[:projects_jira_server_active] += counts[:server].count if counts[:server] + results[:projects_jira_cloud_active] += counts[:cloud].count if counts[:cloud] + if results[:projects_jira_active] == -1 + results[:projects_jira_active] = count(services) + else + results[:projects_jira_active] += count(services) + end + end + + results end def user_preferences_usage |