Sha256: 069575fc3a6967eea8f9af3704026e88c71ddd4d540ad929df613a4cefdff726

Contents?: true

Size: 753 Bytes

Versions: 2

Compression:

Stored size: 753 Bytes

Contents

# frozen_string_literal: true

require "graphlient/adapters/http/http_adapter"

module Decidim
  module ComparativeStats
    class CachedHTTPAdapter < Graphlient::Adapters::HTTP::FaradayAdapter
      def execute(document:, operation_name: nil, variables: {}, context: {})
        body = {}
        # Strip uniq identifier generated by GraphQL class
        body["query"] = document.to_query_string.gsub(/GraphQL__Client__OperationDefinition_[0-9 ]+/, "")
        body["variables"] = variables if variables.any?

        Rails.cache.fetch(
          "graphlient/api_queries/#{url.hash}/#{body.to_json.hash}",
          expires_in: Decidim::ComparativeStats.stats_cache_expiration_time
        ) do
          super
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-comparative_stats-1.1.0 lib/decidim/comparative_stats/cached_http_adapter.rb
decidim-comparative_stats-1.0.1 lib/decidim/comparative_stats/cached_http_adapter.rb