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

Instance Attribute Summary collapse

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.



14
15
16
# File 'app/services/projects/count_service.rb', line 14

def initialize(project)
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



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

def project
  @project
end

Class Method Details

.query(project_ids) ⇒ Object

Raises:

  • (NotImplementedError)


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

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



29
30
31
32
33
# File 'app/services/projects/count_service.rb', line 29

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)


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

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

#relation_for_countObject



18
19
20
# File 'app/services/projects/count_service.rb', line 18

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