Skip to content

Commit

Permalink
Optimize the merge operation of the large number of contributor records.
Browse files Browse the repository at this point in the history
Signed-off-by: EdmondFrank <[email protected]>
  • Loading branch information
EdmondFrank committed Feb 22, 2024
1 parent 2e6417c commit 234b142
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/api/openapi/shared_params/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def extract_params!(params)

def refresh_download_path(state)
blob = state[:blob_id] ? ActiveStorage::Attachment.find_by(blob_id: state[:blob_id], name: 'exports') : nil
state.merge!(download_path: Rails.application.routes.url_helpers.rails_blob_path(blob, only_path: true)) if blob
state.merge!(downdload_path: Rails.application.routes.url_helpers.rails_blob_path(blob, only_path: true)) if blob
state[:download_path] = Rails.application.routes.url_helpers.rails_blob_path(blob, only_path: true) if blob
state[:downdload_path] = Rails.application.routes.url_helpers.rails_blob_path(blob, only_path: true) if blob
state
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/concerns/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def generate_yml_url(agent, branch, path)

def each_patch_with_action(diff_url, &action)
req = { method: :get, url: diff_url }
req.merge!(proxy: PROXY) unless extract_domain(diff_url).start_with?('gitee')
req[:proxy] = PROXY unless extract_domain(diff_url).start_with?('gitee')
diff = RestClient::Request.new(req).execute.body
patches = GitDiffParser.parse(diff)
patches.each do |patch|
Expand All @@ -85,7 +85,7 @@ def analyze_or_submit_yaml_file(analyzer, user_agent, branch, path, extra={})
base_config.merge(yaml_url: yaml_url)
else
req = { method: :get, url: yaml_url }
req.merge!(proxy: PROXY) unless extract_domain(yaml_url).start_with?('gitee')
req[:proxy] = PROXY unless extract_domain(yaml_url).start_with?('gitee')
yaml = YAML.load(RestClient::Request.new(req).execute.body)
base_config.merge(repo_url: yaml['resource_types']['repo_urls'], developers: yaml['developers'] || {})
end
Expand Down
24 changes: 8 additions & 16 deletions app/models/concerns/contributor_enrich.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
module ContributorEnrich
extend ActiveSupport::Concern

MAX_DEPTH = 10
MAX_PER_PAGE = 10000
MAX_DEPTH = 100
MAX_PER_PAGE = 8000

class_methods do
def fetch_contributors_list(repo_urls, begin_date, end_date, label: nil, level: nil)
Expand All @@ -13,7 +13,7 @@ def fetch_contributors_list(repo_urls, begin_date, end_date, label: nil, level:
mileage_step = 0
mileage_types = ['core', 'regular', 'guest']
depth = 0
contributors_list = []
contributors_map = {}

query =
self
Expand All @@ -31,26 +31,18 @@ def fetch_contributors_list(repo_urls, begin_date, end_date, label: nil, level:
.raw_response
.dig('hits', 'hits')
.map do |hit|
contributors_list << hit['_source'].slice(*Types::Meta::ContributorDetailType.fields.keys.map(&:underscore))
row = hit['_source'].slice(*Types::Meta::ContributorDetailType.fields.keys.map(&:underscore))
key = row['contributor']
contributors_map[key] = contributors_map[key] ? merge_contributor(contributors_map[key], row) : row
contribution_count += row['contribution'].to_i
end
query = query.scroll(id: query.scroll_id, timeout: '1m')
depth += 1
break if (query.last_page? || depth > MAX_DEPTH)
end

contributors_list =
contributors_list
.reduce({}) do |map, row|
key = row['contributor']
if !['openharmony_ci'].include?(key)
map[key] = map[key] ? merge_contributor(map[key], row) : row
contribution_count += row['contribution'].to_i
end
map
end

contributors_list =
contributors_list
contributors_map
.sort_by { |_, row| -row['contribution_without_observe'].to_i }
.map do |_, row|
row['mileage_type'] = (mileage_step < 2 && row['contribution_without_observe'] > 0) ?
Expand Down

0 comments on commit 234b142

Please sign in to comment.