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
1
Merge Requests
1
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
nexedi
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
Hide 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
...
@@ -29,17 +29,14 @@ module Github
self
.
reset_callbacks
:validate
self
.
reset_callbacks
:validate
end
end
attr_reader
:project
,
:repository
,
:repo
,
:options
,
:errors
,
attr_reader
:project
,
:repository
,
:repo
,
:options
,
:errors
,
:cached
:cached_label_ids
,
:cached_gitlab_users
,
:cached_user_ids
def
initialize
(
project
,
options
)
def
initialize
(
project
,
options
)
@project
=
project
@project
=
project
@repository
=
project
.
repository
@repository
=
project
.
repository
@repo
=
project
.
import_source
@repo
=
project
.
import_source
@options
=
options
@options
=
options
@cached_label_ids
=
{}
@cached
=
Hash
.
new
{
|
hash
,
key
|
hash
[
key
]
=
Hash
.
new
}
@cached_user_ids
=
{}
@cached_gitlab_users
=
{}
@errors
=
[]
@errors
=
[]
end
end
...
@@ -107,7 +104,7 @@ module Github
...
@@ -107,7 +104,7 @@ module Github
# Cache labels
# Cache labels
project
.
labels
.
select
(
:id
,
:title
).
find_each
do
|
label
|
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
end
end
...
@@ -325,7 +322,7 @@ module Github
...
@@ -325,7 +322,7 @@ module Github
end
end
def
label_ids
(
issuable
)
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
end
def
milestone_id
(
milestone
)
def
milestone_id
(
milestone
)
...
@@ -336,12 +333,12 @@ module Github
...
@@ -336,12 +333,12 @@ module Github
def
user_id
(
user
,
fallback_id
=
nil
)
def
user_id
(
user
,
fallback_id
=
nil
)
return
unless
user
.
present?
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
)
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
[
:gitlab_user_ids
]
[
user
.
id
]
=
gitlab_user_id
.
present?
cached
_user_ids
[
user
.
id
]
=
gitlab_user_id
||
fallback_id
cached
[
:user_ids
]
[
user
.
id
]
=
gitlab_user_id
||
fallback_id
end
end
def
user_id_by_email
(
email
)
def
user_id_by_email
(
email
)
...
@@ -362,7 +359,7 @@ module Github
...
@@ -362,7 +359,7 @@ module Github
end
end
def
format_description
(
body
,
author
)
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
}
"
"*Created by:
#{
author
.
username
}
*
\n\n
#{
body
}
"
end
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