Module: UpdateProjectStatistics

Extended by:
ActiveSupport::Concern
Includes:
AfterCommitQueue
Included in:
Ci::JobArtifact, Ci::PipelineArtifact, Packages::PackageFile, SnippetStatistics
Defined in:
app/models/concerns/update_project_statistics.rb

Overview

This module is providing helpers for updating `ProjectStatistics` with `after_save` and `before_destroy` hooks.

It deals with `ProjectStatistics.increment_statistic` making sure not to update statistics on a cascade delete from the project, and keeping track of value deltas on each save. It updates the DB only when a change is needed.

Example:

module Ci

class JobArtifact < ApplicationRecord
  include UpdateProjectStatistics

  update_project_statistics project_statistics_name: :build_artifacts_size
end

end

Expectation:

  • `statistic_attribute` must be an ActiveRecord attribute

  • The model must implement `project` and `project_id`. i.e. direct Project relationship or delegation

Method Summary

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now