Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-11-27 15:57:51 +0300
committerCindy Pallares <cindy@gitlab.com>2018-11-30 22:26:16 +0300
commit7a50a2a7cd0ba211653107bf9adbb6e77d83f4d2 (patch)
treebb7664c3d4aae08dab7ccacf054cbe3951074de9 /app
parent55d5ae0a8761509e4d4495a7f99136eab7fa5794 (diff)
Merge branch '53778-remove-site-statistics' into 'master'
Remove Site Statistic Closes #53778 See merge request gitlab-org/gitlab-ce!23314
Diffstat (limited to 'app')
-rw-r--r--app/models/project.rb3
-rw-r--r--app/models/site_statistic.rb76
2 files changed, 0 insertions, 79 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 48905547ab4..10792753ade 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -88,9 +88,6 @@ class Project < ActiveRecord::Base
after_create :create_project_feature, unless: :project_feature
- after_create -> { SiteStatistic.track(STATISTICS_ATTRIBUTE) }
- before_destroy -> { SiteStatistic.untrack(STATISTICS_ATTRIBUTE) }
-
after_create :create_ci_cd_settings,
unless: :ci_cd_settings,
if: proc { ProjectCiCdSetting.available? }
diff --git a/app/models/site_statistic.rb b/app/models/site_statistic.rb
deleted file mode 100644
index 3a7912ed53a..00000000000
--- a/app/models/site_statistic.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-# frozen_string_literal: true
-
-class SiteStatistic < ActiveRecord::Base
- # prevents the creation of multiple rows
- default_value_for :id, 1
-
- COUNTER_ATTRIBUTES = %w(repositories_count).freeze
- REQUIRED_SCHEMA_VERSION = 20180629153018
-
- # Tracks specific attribute
- #
- # @param [String] raw_attribute must be one of the values listed in COUNTER_ATTRIBUTES
- def self.track(raw_attribute)
- with_statistics_available(raw_attribute) do |attribute|
- SiteStatistic.update_all(["#{attribute} = #{attribute}+1"])
- end
- end
-
- # Untracks specific attribute
- #
- # @param [String] raw_attribute must be one of the values listed in COUNTER_ATTRIBUTES
- def self.untrack(raw_attribute)
- with_statistics_available(raw_attribute) do |attribute|
- SiteStatistic.update_all(["#{attribute} = #{attribute}-1 WHERE #{attribute} > 0"])
- end
- end
-
- # Wrapper for track/untrack operations with basic validations and enforced requirements
- #
- # @param [String] raw_attribute must be one of the values listed in COUNTER_ATTRIBUTES
- # @yield [String] attribute quoted to be used inside SQL / Arel query
- def self.with_statistics_available(raw_attribute)
- unless raw_attribute.in?(COUNTER_ATTRIBUTES)
- raise ArgumentError, "Invalid attribute: '#{raw_attribute}' to '#{caller_locations(1, 1)[0].label}' method. " \
- "Valid attributes are: #{COUNTER_ATTRIBUTES.join(', ')}"
- end
-
- return unless available?
-
- self.fetch # make sure record exists
-
- attribute = self.connection.quote_column_name(raw_attribute)
-
- # will be running on its own transaction context
- yield(attribute)
- end
-
- # Returns a site statistic record with tracked information
- #
- # @return [SiteStatistic] record with tracked information
- def self.fetch
- transaction(requires_new: true) do
- SiteStatistic.first_or_create!
- end
- rescue ActiveRecord::RecordNotUnique
- retry
- end
-
- # Return whether required schema change is available
- #
- # This is needed in order to degrade gracefully when testing schema migrations
- #
- # @return [Boolean] whether schema is available
- def self.available?
- @available_flag ||= ActiveRecord::Migrator.current_version >= REQUIRED_SCHEMA_VERSION
- end
-
- # Resets cached column information
- #
- # This is called during schema migration specs, in order to reset internal cache state
- def self.reset_column_information
- @available_flag = nil
-
- super
- end
-end