Class: Projects::CountService

Inherits:
BaseCountService show all
Defined in:
app/services/projects/count_service.rb

Overview

Base class for the various service classes that count project data (e.g. issues or forks).

Constant Summary collapse

VERSION =

The version of the cache format. This should be bumped whenever the underlying logic changes. This removes the need for explicitly flushing all caches.

1

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCountService

#cache_options, #count, #count_stored?, #delete_cache, #raw?, #refresh_cache, #uncached_count, #update_cache_for_key

Constructor Details

#initialize(project) ⇒ CountService

Returns a new instance of CountService.


12
13
14
# File 'app/services/projects/count_service.rb', line 12

def initialize(project)
  @project = project
end

Class Method Details

.query(project_ids) ⇒ Object

Raises:

  • (NotImplementedError)

33
34
35
36
37
38
# File 'app/services/projects/count_service.rb', line 33

def self.query(project_ids)
  raise(
    NotImplementedError,
    '"query" must be implemented and return an ActiveRecord::Relation'
  )
end

Instance Method Details

#cache_key(key = nil) ⇒ Object


27
28
29
30
31
# File 'app/services/projects/count_service.rb', line 27

def cache_key(key = nil)
  cache_key = key || cache_key_name

  ['projects', 'count_service', VERSION, @project.id, cache_key]
end

#cache_key_nameObject

Raises:

  • (NotImplementedError)

20
21
22
23
24
25
# File 'app/services/projects/count_service.rb', line 20

def cache_key_name
  raise(
    NotImplementedError,
    '"cache_key_name" must be implemented and return a String'
  )
end

#relation_for_countObject


16
17
18
# File 'app/services/projects/count_service.rb', line 16

def relation_for_count
  self.class.query(@project.id)
end