Skip to content

Commit 04b445a

Browse files
committed
Cache git read for app file example component
1 parent 2276798 commit 04b445a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

app/models/examples/app_file.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def readlines
3737
end
3838

3939
def read
40-
Dir.chdir(ENV.fetch("REPOSITORY_ROOT", ".")) do
41-
`git show #{@revision}:#{@path}`
42-
end
40+
return git_read if @revision == "HEAD" # Don’t cache HEAD
41+
42+
Rails.cache.fetch([:app_file, @revision, @path]) { git_read }
4343
end
4444
alias_method :content, :read
4545

@@ -73,5 +73,13 @@ def source(lines: nil)
7373

7474
content.strip.html_safe
7575
end
76+
77+
private
78+
79+
def git_read
80+
Dir.chdir(ENV.fetch("REPOSITORY_ROOT", ".")) do
81+
`git show #{@revision}:#{@path}`
82+
end
83+
end
7684
end
7785
end

0 commit comments

Comments
 (0)