diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 327d933..623f067 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -4,6 +4,7 @@ KalibroProcessor is the processing web service for Mezuro. == Unreleased +* Improve ModuleResults tree pre_order retrieval performance * Fix possible inconsistency in module result creation (lack of transaction) * Improve acceptance tests by fixing small bugs and adding processing times * Introduce performance tests for Aggregator diff --git a/app/models/module_result.rb b/app/models/module_result.rb index 25c785a..7cbd94e 100644 --- a/app/models/module_result.rb +++ b/app/models/module_result.rb @@ -31,9 +31,10 @@ def to_json(options={}) end def pre_order - root = self - root = root.parent until root.parent.nil? - @pre_order ||= pre_order_traverse(root).to_a + return @pre_order unless @pre_order.nil? + return processing.root_module_result.pre_order unless parent.nil? + + @pre_order = pre_order_traverse(self).to_a end def descendants diff --git a/spec/models/module_result_spec.rb b/spec/models/module_result_spec.rb index 8ae6dbb..15f0686 100644 --- a/spec/models/module_result_spec.rb +++ b/spec/models/module_result_spec.rb @@ -164,11 +164,15 @@ context 'when it is not the root module result' do let!(:root) { FactoryGirl.build(:module_result, id: 1)} let!(:child) { FactoryGirl.build(:module_result, id: 2)} + let!(:processing) { FactoryGirl.build(:processing, root_module_result: root)} + before :each do - child.expects(:parent).twice.returns(root) + child.expects(:parent).returns(root) + child.expects(:processing).returns(processing) root.expects(:parent).returns(nil) root.expects(:children).returns([child]) end + it 'is expected to return the complete pre order tree traversal (from root)' do expect(child.pre_order).to eq([root, child]) end