Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache digest bug? #21951

Open
blackspace opened this issue Oct 13, 2015 · 3 comments
Open

Cache digest bug? #21951

blackspace opened this issue Oct 13, 2015 · 3 comments

Comments

@blackspace
Copy link

In my welcome/index.html.erb file, there are some lines:

<script type="text/javascript">
/*
$(document).ready(function(){
$("a.factory").on("ajax:success",function(event,data){
html=$("#template").render(data.auto_kinds);
$($(this).parent()).children(".auto_kind_list").html(html);
});

});
*/
</script>

When I execute the below command:

$ rake cache_digests:nested_dependencies TEMPLATE=welcome/index
[
"auto_kinds/auto_kind"
]

If I remove the script code, I execute the command:

$ rake cache_digests:nested_dependencies TEMPLATE=welcome/index
[

]

@atul-shimpi
Copy link
Contributor

Its working for me.

Environment

Ubuntu 15.4
Rails 4.2.4
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]

Gemfile.lock
actionpack-action_caching (1.1.1)
actionpack (>= 4.0.0, < 5.0)
actionpack-page_caching (1.0.2)

actionpack (>= 4.0.0, < 5)

Can u check if the index.file is present in the public dir or the dir for caching (if u have specified one)
I guess its not there. If its not there, need to find the reason for it

Let me know ur environment speciallly ruby and rails ver.

@blackspace
Copy link
Author

After I have created a project by 'rails new' ,then execute 'rails g controller welcome index'.
Edit the app/view/welcome/index.html.erb, adding the script codes

<script type="text/javascript">
/*
$(document).ready(function(){
$("a.factory").on("ajax:success",function(event,data){
html=$("#template").render(data.auto_kinds);
$($(this).parent()).children(".auto_kind_list").html(html);
});

});
*/
</script>
$  rake cache_digests:nested_dependencies TEMPLATE=welcome/index
[
  "auto_kinds/auto_kind"
]

My Environment

Ubuntu 15.10
ruby 2.1.4p265
Rails 4.2.4

Gemfile.lock

GEM
  remote: https://ruby.taobao.org/
  specs:
    actionmailer (4.2.4)
      actionpack (= 4.2.4)
      actionview (= 4.2.4)
      activejob (= 4.2.4)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (4.2.4)
      actionview (= 4.2.4)
      activesupport (= 4.2.4)
      rack (~> 1.6)
      rack-test (~> 0.6.2)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (4.2.4)
      activesupport (= 4.2.4)
      builder (~> 3.1)
      erubis (~> 2.7.0)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    activejob (4.2.4)
      activesupport (= 4.2.4)
      globalid (>= 0.3.0)
    activemodel (4.2.4)
      activesupport (= 4.2.4)
      builder (~> 3.1)
    activerecord (4.2.4)
      activemodel (= 4.2.4)
      activesupport (= 4.2.4)
      arel (~> 6.0)
    activesupport (4.2.4)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.3, >= 0.3.4)
      tzinfo (~> 1.1)
    arel (6.0.3)
    binding_of_caller (0.7.2)
      debug_inspector (>= 0.0.1)
    builder (3.2.2)
    byebug (8.0.1)
    coffee-rails (4.1.0)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.9.1.1)
    debug_inspector (0.0.2)
    erubis (2.7.0)
    execjs (2.6.0)
    globalid (0.3.6)
      activesupport (>= 4.1.0)
    i18n (0.7.0)
    jbuilder (2.3.2)
      activesupport (>= 3.0.0, < 5)
      multi_json (~> 1.2)
    jquery-rails (4.0.5)
      rails-dom-testing (~> 1.0)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    json (1.8.3)
    loofah (2.0.3)
      nokogiri (>= 1.5.9)
    mail (2.6.3)
      mime-types (>= 1.16, < 3)
    mime-types (2.6.2)
    mini_portile (0.6.2)
    minitest (5.8.2)
    multi_json (1.11.2)
    nokogiri (1.6.6.2)
      mini_portile (~> 0.6.0)
    rack (1.6.4)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.2.4)
      actionmailer (= 4.2.4)
      actionpack (= 4.2.4)
      actionview (= 4.2.4)
      activejob (= 4.2.4)
      activemodel (= 4.2.4)
      activerecord (= 4.2.4)
      activesupport (= 4.2.4)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.4)
      sprockets-rails
    rails-deprecated_sanitizer (1.0.3)
      activesupport (>= 4.2.0.alpha)
    rails-dom-testing (1.0.7)
      activesupport (>= 4.2.0.beta, < 5.0)
      nokogiri (~> 1.6.0)
      rails-deprecated_sanitizer (>= 1.0.1)
    rails-html-sanitizer (1.0.2)
      loofah (~> 2.0)
    railties (4.2.4)
      actionpack (= 4.2.4)
      activesupport (= 4.2.4)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (10.4.2)
    rdoc (4.2.0)
      json (~> 1.4)
    sass (3.4.19)
    sass-rails (5.0.4)
      railties (>= 4.0.0, < 5.0)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (>= 1.1, < 3)
    sdoc (0.4.1)
      json (~> 1.7, >= 1.7.7)
      rdoc (~> 4.0)
    spring (1.4.0)
    sprockets (3.4.0)
      rack (> 1, < 3)
    sprockets-rails (2.3.3)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (>= 2.8, < 4.0)
    sqlite3 (1.3.11)
    thor (0.19.1)
    thread_safe (0.3.5)
    tilt (2.0.1)
    turbolinks (2.5.3)
      coffee-rails
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    uglifier (2.7.2)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    web-console (2.2.1)
      activemodel (>= 4.0)
      binding_of_caller (>= 0.7.2)
      railties (>= 4.0)
      sprockets-rails (>= 2.0, < 4.0)
PLATFORMS
  ruby
DEPENDENCIES
  byebug
  coffee-rails (~> 4.1.0)
  jbuilder (~> 2.0)
  jquery-rails
  rails (= 4.2.4)
  sass-rails (~> 5.0)
  sdoc (~> 0.4.0)
  spring
  sqlite3
  turbolinks
  uglifier (>= 1.3.0)
  web-console (~> 2.0)
BUNDLED WITH
   1.10.6

@romaimperator
Copy link
Contributor

I have run into a related but different problem myself. I am fairly certain that it is caused by the line:
html=$("#template").render(data.auto_kinds);
being present in your index template.

The problem occurs here in the dependency tracker. The value of source is the content of your index template so the regex matches to that render call. Then the later lines match data.auto_kinds and assume the variable being rendered (like if you had render @product) and adds the dependency "autokinds/autokind".

romaimperator added a commit to romaimperator/rails that referenced this issue Feb 27, 2018
This occurs because of how the dependency tracker looks for render calls
in templates.

I ran into this bug when I was using a decorator object that defined
to_partial_path. I had in my view a render call like this
<%= render MyDecorator.new(model_object) %>
and I also had calls to the cache helper in the same template. When
the cache helper was getting the dependencies to use for digesting,
I saw in the log "Couldn't find template for digesting: news/new".
I was able to track this down to how the dependency tracker finds
render calls and then processes them. The relevant code is here
https://github.com/rails/rails/blob/v5.0.0.beta2/actionview/lib/action_view/dependency_tracker.rb#L118.

I believe issue rails#21951 is related and is also will be fixed by this.

If this is present in a view template:

<script>
  var render = document.getElementById('#render');
  render(data.autokinds);
</script>

<div id="render" data-auto_kinds="value">
  <h1>hello</h1>
</div>

<%= render ApplicationHelper::ClassWithPartialPath.new %>
<%= render ClassWithPartialPath.new %>
<%= render ApplicationHelper::employee %>

Then running
bundle exec rake cache_digests:dependencies TEMPLATE=that_template_name
will produce the following list:
=> [
  "autokinds/autokind",
  "static/ data-auto_kinds=", # static is the name of controller I chose
  "ApplicationHelpers/ApplicationHelper",
  "news/new"
]

After the fix, running the cache_digests command on the same template
will produce:

=> [
  "employees/employee"
]

This is matching the last render call, the scoped access of a record
in the ApplicationHelper. I'm not sure that anyone actually uses that
but it is a side-effect fix to prevent the 3rd dependency,
"ApplicationHelpers/ApplicationHelper", from showing as a dependency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants