Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ nav_order: 6

## main

* Speed up cold cache digests by skipping the `# Template Dependency:` scan for sources that declare none, and by not translating class names in synthetic templates, which only declare paths.

*Erik Axel Nielsen*

## 4.22.0

* Comment on release pull requests with benchmark results compared to the previous release.
Expand Down
6 changes: 4 additions & 2 deletions lib/view_component/cache_digest/dependency_tracking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def find_dependencies(name, template, view_paths = nil)
dependencies = super
source = template.source

# Synthetic templates already declare every dependency found in their
# sources, as paths.
next dependencies if name.start_with?("#{CacheDigest::VIRTUAL_PATH_PREFIX}/")

# `# Template Dependency: SomeComponent` names a class, which Rails
# would resolve as a template path and never find. Swap it for the path
# the component is digested under, so the declaration resolves instead
Expand All @@ -29,8 +33,6 @@ def find_dependencies(name, template, view_paths = nil)
dependencies = dependencies - [declared] + [virtual_path]
end

# Synthetic templates already declare every dependency found in their sources.
next dependencies if name.start_with?("#{CacheDigest::VIRTUAL_PATH_PREFIX}/")
next dependencies unless CacheDigest.template_dependencies?(source, template.handler)

component_paths, inferred_partials =
Expand Down
4 changes: 4 additions & 0 deletions lib/view_component/cache_digest/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ def template_sources(component)

def explicit_dependencies(sources)
sources.flat_map { |source|
# A cheap check first: most sources declare nothing, and the
# pattern is slow to scan for in sources with many comments.
next [] unless source.include?("Template Dependency:")

declared = source.scan(CacheDigest::EXPLICIT_DEPENDENCY).flatten

# Component class names are translated to the path they're digested
Expand Down
Loading