summaryrefslogtreecommitdiff
path: root/lib/github
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-24 20:00:11 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-24 20:00:11 -0300
commit1f498b73dabfd1bb1f2beb9cc6639db4e433ad28 (patch)
tree20d765542892e5a1648e0a7101d0e8cf152e0fb2 /lib/github
parent275f00ee88cb9ef6ae3ae7879498a0ed4f448681 (diff)
downloadgitlab-ce-1f498b73dabfd1bb1f2beb9cc6639db4e433ad28.tar.gz
Use only one cache hash with with a hash initializer by default
Diffstat (limited to 'lib/github')
-rw-r--r--lib/github/import.rb19
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/github/import.rb b/lib/github/import.rb
index cbda4be2576..8ffbb21bac0 100644
--- a/lib/github/import.rb
+++ b/lib/github/import.rb
@@ -29,17 +29,14 @@ module Github
self.reset_callbacks :validate
end
- attr_reader :project, :repository, :repo, :options, :errors,
- :cached_label_ids, :cached_gitlab_users, :cached_user_ids
+ attr_reader :project, :repository, :repo, :options, :errors, :cached
def initialize(project, options)
@project = project
@repository = project.repository
@repo = project.import_source
@options = options
- @cached_label_ids = {}
- @cached_user_ids = {}
- @cached_gitlab_users = {}
+ @cached = Hash.new { |hash, key| hash[key] = Hash.new }
@errors = []
end
@@ -107,7 +104,7 @@ module Github
# Cache labels
project.labels.select(:id, :title).find_each do |label|
- @cached_label_ids[label.title] = label.id
+ cached[:label_ids][label.title] = label.id
end
end
@@ -325,7 +322,7 @@ module Github
end
def label_ids(issuable)
- issuable.map { |attrs| cached_label_ids[attrs.fetch('name')] }.compact
+ issuable.map { |attrs| cached[:label_ids][attrs.fetch('name')] }.compact
end
def milestone_id(milestone)
@@ -336,12 +333,12 @@ module Github
def user_id(user, fallback_id = nil)
return unless user.present?
- return cached_user_ids[user.id] if cached_user_ids.key?(user.id)
+ return cached[:user_ids][user.id] if cached[:user_ids].key?(user.id)
gitlab_user_id = user_id_by_external_uid(user.id) || user_id_by_email(user.email)
- cached_gitlab_users[user.id] = gitlab_user_id.present?
- cached_user_ids[user.id] = gitlab_user_id || fallback_id
+ cached[:gitlab_user_ids][user.id] = gitlab_user_id.present?
+ cached[:user_ids][user.id] = gitlab_user_id || fallback_id
end
def user_id_by_email(email)
@@ -362,7 +359,7 @@ module Github
end
def format_description(body, author)
- return body if cached_gitlab_users[author.id]
+ return body if cached[:gitlab_user_ids][author.id]
"*Created by: #{author.username}*\n\n#{body}"
end