Skip to content

Compatability with Tire collections #12

@xpac27

Description

@xpac27

Hi ! Thanks for this awesome gem !

I noticed it's not compatible with Tire's collections (the ElasticSearch DSL). For example, if I request a collection of items from tire, then render this collection's partials with cache activated it will work at first. But once I reload the page I get:

NoMethodError: undefined method `delete_if' for #<Tire::Results::Collection:0x007ff3b7845fa0>

This is because cached items are removed from the collection in render_collection_with_multi_fetch_cache using the delete method from ActiveRecords. It doesn't work with Tire's collections since they don't implement this method. However, Tire's collections support Enumerable so it's easy to add the delete method :

module Tire
  module Results
    class Collection
      def delete item
        @results = @results.reject {|i| i == item}
      end
    end
  end
end

I'm not sure if this is a Tire incompatibility or a multi_fetch_fragments one but has you mentioned, in an other issue, that using delete is pretty dangerous, I though it might be useful to use an other technique. But I'm new with your gem so maybe I'm totally wrong :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions