Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
1f498b73
Commit
1f498b73
authored
Apr 24, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use only one cache hash with with a hash initializer by default
parent
275f00ee
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
lib/github/import.rb
lib/github/import.rb
+8
-11
No files found.
lib/github/import.rb
View file @
1f498b73
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment