Class: Gitlab::GithubImport::IssuableFinder
- Inherits:
-
Object
- Object
- Gitlab::GithubImport::IssuableFinder
- Defined in:
- lib/gitlab/github_import/issuable_finder.rb
Overview
IssuableFinder can be used for caching and retrieving database IDs for issuable objects such as issues and pull requests. By caching these IDs we remove the need for running a lot of database queries when importing GitHub projects.
Constant Summary collapse
- CACHE_KEY =
The base cache key to use for storing/retrieving issuable IDs.
'github-import/issuable-finder/%{project}/%{type}/%{iid}'
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
-
#cache_database_id(database_id) ⇒ Object
Associates the given database ID with the current object.
-
#database_id ⇒ Object
Returns the database ID for the object.
-
#initialize(project, object) ⇒ IssuableFinder
constructor
project - An instance of ‘Project`.
Constructor Details
#initialize(project, object) ⇒ IssuableFinder
project - An instance of ‘Project`. object - The object to look up or set a database ID for.
17 18 19 20 |
# File 'lib/gitlab/github_import/issuable_finder.rb', line 17 def initialize(project, object) @project = project @object = object end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
10 11 12 |
# File 'lib/gitlab/github_import/issuable_finder.rb', line 10 def object @object end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
10 11 12 |
# File 'lib/gitlab/github_import/issuable_finder.rb', line 10 def project @project end |
Instance Method Details
#cache_database_id(database_id) ⇒ Object
Associates the given database ID with the current object.
database_id - The ID of the corresponding database row.
34 35 36 |
# File 'lib/gitlab/github_import/issuable_finder.rb', line 34 def cache_database_id(database_id) Gitlab::Cache::Import::Caching.write(cache_key, database_id, timeout: timeout) end |
#database_id ⇒ Object
Returns the database ID for the object.
This method will return ‘nil` if no ID could be found.
25 26 27 28 29 |
# File 'lib/gitlab/github_import/issuable_finder.rb', line 25 def database_id val = Gitlab::Cache::Import::Caching.read(cache_key, timeout: timeout) val.to_i if val.present? end |