Class: Projects::FetchStatisticsIncrementService

Inherits:
Object
  • Object
show all
Defined in:
app/services/projects/fetch_statistics_increment_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ FetchStatisticsIncrementService

Returns a new instance of FetchStatisticsIncrementService.



7
8
9
# File 'app/services/projects/fetch_statistics_increment_service.rb', line 7

def initialize(project)
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



5
6
7
# File 'app/services/projects/fetch_statistics_increment_service.rb', line 5

def project
  @project
end

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
# File 'app/services/projects/fetch_statistics_increment_service.rb', line 11

def execute
  increment_fetch_count_sql = <<~SQL
    INSERT INTO #{table_name} (project_id, date, fetch_count)
    VALUES (#{project.id}, '#{Date.today}', 1)
    ON CONFLICT (project_id, date) DO UPDATE SET fetch_count = #{table_name}.fetch_count + 1
  SQL

  ProjectDailyStatistic.connection.execute(increment_fetch_count_sql)
end