Class: Gitlab::GithubImport::EventsCache
- Inherits:
-
Object
- Object
- Gitlab::GithubImport::EventsCache
- Defined in:
- lib/gitlab/github_import/events_cache.rb
Constant Summary collapse
- MAX_NUMBER_OF_EVENTS =
100- MAX_EVENT_SIZE =
100.kilobytes
Instance Method Summary collapse
-
#add(record, issue_event) ⇒ Object
Add issue event as JSON to the cache.
-
#delete(record) ⇒ Object
Deletes the cache.
-
#events(record) ⇒ Object
Reads issue events from cache.
-
#initialize(project) ⇒ EventsCache
constructor
A new instance of EventsCache.
Constructor Details
#initialize(project) ⇒ EventsCache
Returns a new instance of EventsCache.
9 10 11 |
# File 'lib/gitlab/github_import/events_cache.rb', line 9 def initialize(project) @project = project end |
Instance Method Details
#add(record, issue_event) ⇒ Object
Add issue event as JSON to the cache
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gitlab/github_import/events_cache.rb', line 17 def add(record, issue_event) json = issue_event.to_hash.to_json if json.bytesize > MAX_EVENT_SIZE Logger.warn( message: 'Event too large to cache', project_id: project.id, github_identifiers: issue_event.github_identifiers ) return end Gitlab::Cache::Import::Caching.list_add(events_cache_key(record), json, limit: MAX_NUMBER_OF_EVENTS) end |
#delete(record) ⇒ Object
Deletes the cache
48 49 50 |
# File 'lib/gitlab/github_import/events_cache.rb', line 48 def delete(record) Gitlab::Cache::Import::Caching.del(events_cache_key(record)) end |
#events(record) ⇒ Object
Reads issue events from cache
37 38 39 40 41 42 43 |
# File 'lib/gitlab/github_import/events_cache.rb', line 37 def events(record) events = Gitlab::Cache::Import::Caching.values_from_list(events_cache_key(record)).map do |event| Representation::IssueEvent.from_json_hash(Gitlab::Json.parse(event)) end events.sort_by(&:created_at) end |