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

Jb/649 horizontal caching #60

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions vendor/engines/your_platform/app/models/dag_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def delete_cache
super
if direct?
ancestor.delete_cache
ancestor.ancestors.collect { |x| x.delete_cache }
descendant.delete_cache
end
end
Expand Down
6 changes: 5 additions & 1 deletion vendor/engines/your_platform/app/models/structureable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def children_cache_key
def destroy_links
self.destroy_dag_links
end


def descendants
cached { super }
end

end
end
61 changes: 61 additions & 0 deletions vendor/engines/your_platform/spec/models/structureable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,68 @@
@node.destroy
@parent.links_as_parent.count.should == 0
end

it "should have children" do
@parent = create( :page )
@parent.child_pages << @node
@parent.children.count.should == 1
end

it "should update the children" do
@parent = create( :page )
@parent.child_pages << @node
@parent.children.count.should == 1
@brother = create( :page )
@parent.child_pages << @brother
@parent.children.count.should == 2
end

it "should have descendants" do
@parent = create( :page )
@parent.child_pages << @node
@grandparent = create( :page )
@grandparent.child_pages << @parent
@grandparent.descendants.count.should == 2
end

it "should update the descendants after a reload" do
@parent = create( :page )
@parent.child_pages << @node
@grandparent = create( :page )
@grandparent.child_pages << @parent
@grandparent.descendants.count.should == 2
@brother = create( :page )
@parent.child_pages << @brother
@parent.reload
@grandparent.reload
@grandparent.descendants.count.should == 3
end

it "should cache the descendants" do
@parent = create( :page )
@parent.child_pages << @node
@grandparent = create( :page )
@grandparent.child_pages << @parent
@grandparent.descendants.count.should == 2
@grandparent.reload
t1 = Time.now
@grandparent.descendants.count.should == 2
t2 = Time.now
t3 = t2-t1
# without caching it took on my machine 0.006 seconds, on travis 0.004
# With caching it took 0.003 seconds, on travis 0.000x seconds
t3.should < 0.004
end

it "should update content of descendants" do
@parent = create( :page )
@parent.child_pages << @node
@grandparent = create( :page )
@grandparent.child_pages << @parent
@grandparent.descendants
@node.update_attributes title:"Updated"
@grandparent.descendants.count { |x| x.title == "Updated" }.should == 1
end
end

end