lib/nitro_pg_cache/viewer_ext.rb
def db_cache_collection_s( options )
      collection = options[:collection]
      # nitro_cache_key - same across all collection
      nitro_cache_key = options.to_nitro_cache_key
      result = ""

      aggr_result = collection.aggregate_collection( nitro_cache_key )
      if aggr_result['has_nulls'] == 't'
        # this is place where NitroPartial creates new partials info in DB
        @current_cache_aggregator = { nitro_partial_id: NitroPartial.get_partial( options[:partial], options ).id,
                                      nitro_cache_key: nitro_cache_key,
                                      reverse: false,
                                      caches: [] }

        result = render( partial: options[:partial],
                         #because of select nitro_cached_value we need to add select( 'all.*' )
                         collection: collection.select_all_if_empty
                                         .select_nitro_cache
                                         .outer_join_partials(nitro_cache_key),
                         as: options[:as],
                         locals: {
                             locals: options[:locals]
                         }
        )
        # Нужно массив все таки переделать в хеш на случай повторений в коллекции
        collection.klass.nitro_cache_bulk_insert( @current_cache_aggregator )

      else
        result = aggr_result['str_agg'].try(:html_safe)
      end

      #NitroCache.where( nitro_cacheable: collection, nitro_cache_key: nitro_cache_key) breaks on complex collections
      NitroCache.where( nitro_cacheable_type: collection.base_class,
                        nitro_cacheable_id: collection.base_class
                                                .from( "(#{collection.to_sql }) #{collection.table_name}" ).select(:id),
                        nitro_cache_key: nitro_cache_key )
          .update_all(viewed_at: Time.now)

      # alternative way to
      #ActiveRecord::Base.connection.execute( <<UPDATE_SQL
      #          UPDATE "nitro_cahes"
      #          SET "viewed_at" = '#{Time.now}'
      #          WHERE "nitro_partials"."id" IN (
      #             SELECT "nitro_caches"."id" FROM (#{collection.outer_join_partials(nitro_cache_key).unscope(:select).select('"nitro_caches"."id"').to_sql}) as db_cache_partials )
      # UPDATE_SQL
      #       )

      result
    end
# cache_key generated with cache_by and locals
# straight cache. same logic as usual cache.
cache_key generated with cache_by and locals
straight cache. same logic as usual cache.
cache_key generated with cache_by and locals straight cache . same logic as usual cache .
def db_cache_collection_s( options )
      collection = options[:collection]
      nitro_cache_key = options.to_nitro_cache_key
      result = ""
      aggr_result = collection.aggregate_collection( nitro_cache_key )
      if aggr_result['has_nulls'] == 't'
        @current_cache_aggregator = { nitro_partial_id: NitroPartial.get_partial( options[:partial], options ).id,
                                      nitro_cache_key: nitro_cache_key,
                                      reverse: false,
                                      caches: [] }
        result = render( partial: options[:partial],
                         collection: collection.select_all_if_empty
                                         .select_nitro_cache
                                         .outer_join_partials(nitro_cache_key),
                         as: options[:as],
                         locals: {
                             locals: options[:locals]
                         }
        )
        collection.klass.nitro_cache_bulk_insert( @current_cache_aggregator )
      else
        result = aggr_result['str_agg'].try(:html_safe)
      end
      NitroCache.where( nitro_cacheable_type: collection.base_class,
                        nitro_cacheable_id: collection.base_class
                                                .from( "(#{collection.to_sql }) #{collection.table_name}" ).select(:id),
                        nitro_cache_key: nitro_cache_key )
          .update_all(viewed_at: Time.now)
      result
    end
def db_cache_collection_s ( options ) collection = options [ :collection ] nitro_cache_key = options . to_nitro_cache_key result = "" aggr_result = collection . aggregate_collection ( nitro_cache_key ) if aggr_result [ 'has_nulls' ] == 't' @current_cache_aggregator = { nitro_partial_id : NitroPartial . get_partial ( options [ :partial ] , options ) . id , nitro_cache_key : nitro_cache_key , reverse : false , caches : [ ] } result = render ( partial : options [ :partial ] , collection : collection . select_all_if_empty . select_nitro_cache . outer_join_partials ( nitro_cache_key ) , as : options [ :as ] , locals : { locals : options [ :locals ] } ) collection . klass . nitro_cache_bulk_insert ( @current_cache_aggregator ) else result = aggr_result [ 'str_agg' ] . try ( :html_safe ) end NitroCache . where ( nitro_cacheable_type : collection . base_class , nitro_cacheable_id : collection . base_class . from ( "(#{collection.to_sql }) #{collection.table_name}" ) . select ( :id ) , nitro_cache_key : nitro_cache_key ) . update_all ( viewed_at : Time . now ) result end
cache_key generated with cache_by and locals
straight cache.
cache_key generated with cache_by and locals straight cache .
# nitro_cache_key - same across all collection # this is place where NitroPartial creates new partials info in DB #because of select nitro_cached_value we need to add select( 'all.*' ) # Нужно массив все таки переделать в хеш на случай повторений в коллекции #NitroCache.where( nitro_cacheable: collection, nitro_cache_key: nitro_cache_key) breaks on complex collections # alternative way to #ActiveRecord::Base.connection.execute( <<UPDATE_SQL #          UPDATE "nitro_cahes" #          SET "viewed_at" = '#{Time.now}' #          WHERE "nitro_partials"."id" IN ( #             SELECT "nitro_caches"."id" FROM (#{collection.outer_join_partials(nitro_cache_key).unscope(:select).select('"nitro_caches"."id"').to_sql}) as db_cache_partials ) # UPDATE_SQL #       )
options