Browse Source

Caching of posts

pull/48/head
Stephen 1 month ago
parent
commit
3a493a2f67
5 changed files with 56 additions and 50 deletions
  1. +1
    -1
      Gemfile.lock
  2. +1
    -1
      app/views/blog/summary.html.erb
  3. +17
    -15
      app/views/post/get.html.erb
  4. +36
    -32
      app/views/post/index.html.erb
  5. +1
    -1
      config/environments/production.rb

+ 1
- 1
Gemfile.lock View File

@ -284,7 +284,7 @@ DEPENDENCIES
webpacker (~> 4.0)
RUBY VERSION
ruby 2.6.4p104
ruby 2.6.3p62
BUNDLED WITH
2.0.2

+ 1
- 1
app/views/blog/summary.html.erb View File

@ -1,5 +1,5 @@
<hr>
<%= render @posts, short: true, blog_link: true, blog_name: true %>
<%= render partial: @posts, cached: current_user.nil?, locals: { short: true, blog_link: true, blog_name: true } %>
<% provide :desc, "This page is a summary of all blogs on the site." %>
<div class="footer">
<ul class="pagination">


+ 17
- 15
app/views/post/get.html.erb View File

@ -1,17 +1,19 @@
<% provide(:desc, truncate(
strip_tags(parse_markdown(@post.body)),
length: 150)) %>
<%= render @post, detailed: true %>
<% cache_if current_user.nil?, @post do %>
<% provide(:desc, truncate(
strip_tags(parse_markdown(@post.body)),
length: 150)) %>
<%= render @post, detailed: true %>
<h3>Leave a comment</h3>
<% unless current_user.nil? %>
<%= form_for @comment, url: comment_path(post_id: @post.id) do |f| %>
<%= f.text_area :body, style: "width: 75%; height: 10em;" %>
<br>
<%= f.submit "Post", class: "btn btn-sm btn-primary" %>
<% end %>
<% else %>
You have to sign in to leave a comment.
<% end %>
<h3>Leave a comment</h3>
<% unless current_user.nil? %>
<%= form_for @comment, url: comment_path(post_id: @post.id) do |f| %>
<%= f.text_area :body, style: "width: 75%; height: 10em;" %>
<br>
<%= f.submit "Post", class: "btn btn-sm btn-primary" %>
<% end %>
<% else %>
You have to sign in to leave a comment.
<% end %>
<%= render @comments, reply_to: @reply_to %>
<%= render @comments, reply_to: @reply_to %>
<% end %>

+ 36
- 32
app/views/post/index.html.erb View File

@ -1,36 +1,40 @@
<%= content_for :head do %>
<%= auto_discovery_link_tag :rss, blog_url(blog_name: @blog.urlName, format: :rss) %>
<link href="/open-iconic/font/css/open-iconic.css" rel="stylesheet">
<% end %>
<% cache_if current_user.nil?, [@blog, @posts, @page] do %>
<%= content_for :head do %>
<%= auto_discovery_link_tag :rss, blog_url(blog_name: @blog.urlName, format: :rss) %>
<link href="/open-iconic/font/css/open-iconic.css" rel="stylesheet">
<% end %>
<% provide(:desc, @blog.slogan) %>
<a style="float: right;" href="<%= blog_url(blog_name: @blog.urlName, format: :rss) %>">
<span style="color: orange;" class="oi" data-glyph="rss" title="rss" aria-hidden="true"></span>
</a>
<br>
<hr>
<%= render @posts, short: true %>
<% provide(:desc, @blog.slogan) %>
<a style="float: right;" href="<%= blog_url(blog_name: @blog.urlName, format: :rss) %>">
<span style="color: orange;" class="oi" data-glyph="rss" title="rss" aria-hidden="true"></span>
</a>
<br>
<hr>
<% if @posts.size > 0 %>
<%= render partial: @posts, cached: current_user.nil?, locals: { short: true } %>
<% end %>
<div class="footer">
<ul class="pagination">
<li class="page-item <%= @has_prev ? "" : "disabled" %>">
<%= link_to "<", {page: @page - 1}, {class: "page-link"} %>
</li>
<div class="footer">
<ul class="pagination">
<li class="page-item <%= @has_prev ? "" : "disabled" %>">
<%= link_to "<", {page: @page - 1}, {class: "page-link"} %>
</li>
<% (1..@page_count).to_a.each do |x| %>
<% if x == @page %>
<li class="page-item active">
<a class="page-link" href="#"><%= x %></a>
</li>
<% else %>
<li class="page-item">
<%= link_to(x, {page: x}, {class: "page-link"}) %>
</li>
<% end %>
<% end %>
<% (1..@page_count).to_a.each do |x| %>
<% if x == @page %>
<li class="page-item active">
<a class="page-link" href="#"><%= x %></a>
</li>
<% else %>
<li class="page-item">
<%= link_to(x, {page: x}, {class: "page-link"}) %>
</li>
<% end %>
<% end %>
<li class="page-item <%= @has_next ? "" : "disabled" %>">
<%= link_to ">", {page: @page + 1}, {class: "page-link"} %>
</li>
</ul>
</div>
<li class="page-item <%= @has_next ? "" : "disabled" %>">
<%= link_to ">", {page: @page + 1}, {class: "page-link"} %>
</li>
</ul>
</div>
<% end %>

+ 1
- 1
config/environments/production.rb View File

@ -54,7 +54,7 @@ Rails.application.configure do
config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
config.cache_store = :mem_cache_store
config.assets.js_compressor = Uglifier.new(harmony: true)


Loading…
Cancel
Save