8

I have a template that displays a list of events

<tbody>
<%= render partial: 'event', collection: events, cached: true %>
</tbody>

The partial event:

<% cache event do %>
  <tr>
    <td>
      Something
    </td>
    <td>
      <%= render 'identifiable_link_with_tag', identifiable: event.identifiable %>
    </td>
  </tr>
<% end %>

The partial identifiable_link_with_tag:

<% cache identifiable do %>
    <span class="badge badge-info"><%= identifiable.type %></span> <%= link_to identifiable.identifier, identifiable %>
<% end %>

Now, the odd thing is what follows. Sometimes I notice in the events view that for some events another partial (identifiable) is rendered instead of identifiable_link_with_tag: _identifiable. This seems very odd, and on a page that lists 25 events, this would only happen for 1 or 2 or 3 (or 0) events.

So in short, it seems that sometimes the wrong identifiable is rendered. I do use Rails fragment caching, so that may be a factor. Am I missing something or have I encountered a Rails bug? This issue is very hard to reproduce in development, thus hard to debug.

edwardmp
  • 6,339
  • 5
  • 50
  • 77
  • Are you getting the wrong `event` partial or `identifiable_link_with_tag`? What exactly is wrong? One thing with Russian doll caching is that update to any `identifiable` will not expire the `event` partial it is nested in unless that event is `touched`. Not sure if that's the problem you're facing. – EJAg Oct 17 '17 at 19:01
  • @EJ2015 it's not an issue regarding outdated information, I am aware of that. Instead of the partial `identifiable_link_with_tag`, the partial for `identifiable` itself is rendered (see updated answer) – edwardmp Oct 17 '17 at 19:28
  • Are you also caching the partial `identifiable`? Maybe that is using the same cache key as the corresponding `identifiable_link_with_tag`, if you're also doing `cache identifiable` there too? If so you can try using a custom cache key for one of them. – EJAg Oct 17 '17 at 20:50
  • @EJ2015 Yes I am also caching `identifiable` partial! I was thinking of some kind of cache key collision too, but if so is this a bug in Rails or not? – edwardmp Oct 17 '17 at 21:47
  • The key should include a template digest. So this seems unlikely. But this is the only thing I can think of. Can you test it? – EJAg Oct 17 '17 at 22:31
  • Please check server logs carefully and try to update the snippet when it renders different partial than the one you mentioned in views. @edwardmp – Narasimha Reddy - Geeker Oct 23 '17 at 07:27
  • Consider adding the content of the `identifiable_link_with_tag` and `identifiable` partials. This will probably help with debugging. – ekampp Jul 08 '19 at 21:46

0 Answers0