Sha256: 75a5ba427720f74659897ce7c320944851176322dabebe0d46a73c2927b20d1d

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

module Timescaledb
  class Stats
    class Chunks
      # @param [Array<String>] hypertables The list of hypertable names.
      # @param [Timescaledb:Connection] connection The PG connection.
      def initialize(hypertables = [], connection = Timescaledb.connection)
        @connection = connection
        @hypertables = hypertables
      end

      delegate :query_count, to: :@connection

      # @return [Hash] The chunks stats
      def to_h
        { total: total, compressed: compressed, uncompressed: uncompressed }
      end

      private

      def total
        query_count(base_query, [@hypertables])
      end

      def compressed
        compressed_query = [base_query, 'is_compressed'].join(' AND ')

        query_count(compressed_query, [@hypertables])
      end

      def uncompressed
        uncompressed_query = [base_query, 'NOT is_compressed'].join(' AND ')

        query_count(uncompressed_query, [@hypertables])
      end

      def base_query
        "SELECT COUNT(1) FROM timescaledb_information.chunks WHERE hypertable_name IN ($1)"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
timescaledb-0.3.0 lib/timescaledb/stats/chunks.rb
timescaledb-0.2.9 lib/timescaledb/stats/chunks.rb
timescaledb-0.2.8 lib/timescaledb/stats/chunks.rb