Skip to content

Commit

Permalink
Caching (SpinaCMS#307)
Browse files Browse the repository at this point in the history
* Some caching test

* Memoization for current_page

* Version schema db
  • Loading branch information
sidkola authored and Bramjetten committed Oct 14, 2017
1 parent ec09b08 commit ca62291
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/models/spina/navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ class Navigation < ApplicationRecord

validates :name, :label, presence: true
validates :name, uniqueness: true

def cache_key
super + "_" + Globalize.locale.to_s
end
end
end
2 changes: 1 addition & 1 deletion app/models/spina/navigation_item.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Spina
class NavigationItem < ApplicationRecord
belongs_to :navigation
belongs_to :navigation, touch: true
belongs_to :page

has_ancestry orphan_strategy: :adopt
Expand Down
5 changes: 5 additions & 0 deletions app/models/spina/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Page < ApplicationRecord

# Save children to update all materialized_paths
after_save :save_children
after_save :touch_navigations

# Create a 301 redirect if materialized_path changed
after_save :rewrite_rule
Expand Down Expand Up @@ -92,6 +93,10 @@ def view_template_page_parts(theme)

private

def touch_navigations
navigations.update_all(updated_at: Time.zone.now)
end

def rewrite_rule
RewriteRule.create(old_path: old_path, new_path: materialized_path) if old_path != materialized_path
end
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170803183152) do
ActiveRecord::Schema.define(version: 8) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down

0 comments on commit ca62291

Please sign in to comment.