performance improvements as described in #383
This commit is contained in:
parent
9613058b97
commit
23600edb1f
@ -44,7 +44,7 @@ PATH
|
||||
locomotive_liquid (= 2.2.2)
|
||||
mimetype-fu (~> 0.1.2)
|
||||
mongo (~> 1.5.2)
|
||||
mongoid (~> 2.4.6)
|
||||
mongoid (~> 2.4.9)
|
||||
multi_json (= 1.2.0)
|
||||
rack-cache (~> 1.1)
|
||||
rails (~> 3.2.3)
|
||||
@ -115,7 +115,7 @@ GEM
|
||||
childprocess (0.3.1)
|
||||
ffi (~> 1.0.6)
|
||||
chunky_png (1.2.5)
|
||||
codemirror-rails (2.23)
|
||||
codemirror-rails (2.24)
|
||||
railties (~> 3.0)
|
||||
coffee-rails (3.2.2)
|
||||
coffee-script (>= 2.2.0)
|
||||
@ -215,7 +215,7 @@ GEM
|
||||
mocha (0.9.12)
|
||||
mongo (1.5.2)
|
||||
bson (= 1.5.2)
|
||||
mongoid (2.4.8)
|
||||
mongoid (2.4.9)
|
||||
activemodel (~> 3.1)
|
||||
mongo (~> 1.3)
|
||||
tzinfo (~> 0.3.22)
|
||||
|
@ -24,10 +24,6 @@ class Locomotive.Views.Shared.Fields.ManyToManyView extends Backbone.View
|
||||
@collection = @model.get(@options.name)
|
||||
@all_entries = @options.all_entries
|
||||
|
||||
window.collection = @collection
|
||||
window.bar = @all_entries
|
||||
window.model = @model
|
||||
|
||||
render: ->
|
||||
$(@el).html(@template()())
|
||||
|
||||
|
@ -27,6 +27,10 @@ module Locomotive
|
||||
end
|
||||
|
||||
visible << content_type
|
||||
|
||||
end.each do |content_type|
|
||||
# make sure to have a fresh copy of the content types because for now we don't have the full content types (ie: content_types.only(...))
|
||||
::Mongoid::IdentityMap.remove(content_type)
|
||||
end
|
||||
|
||||
if visible.size > 0
|
||||
|
@ -86,7 +86,7 @@ module Locomotive
|
||||
end
|
||||
|
||||
def as_json(options = {})
|
||||
self.to_presenter.as_json
|
||||
self.to_presenter(options).as_json
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -19,6 +19,9 @@ module Locomotive
|
||||
## indexes ##
|
||||
index :position
|
||||
index [[:depth, Mongo::ASCENDING], [:position, Mongo::ASCENDING]]
|
||||
|
||||
alias_method_chain :rearrange, :identity_map
|
||||
alias_method_chain :rearrange_children, :identity_map
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
@ -101,6 +104,16 @@ module Locomotive
|
||||
|
||||
protected
|
||||
|
||||
def rearrange_with_identity_map
|
||||
::Mongoid::IdentityMap.clear
|
||||
rearrange_without_identity_map
|
||||
end
|
||||
|
||||
def rearrange_children_with_identity_map
|
||||
self.children.reset
|
||||
rearrange_children_without_identity_map
|
||||
end
|
||||
|
||||
def persist_depth
|
||||
self.attributes['depth'] = self.depth
|
||||
self.depth_will_change!
|
||||
|
@ -54,8 +54,12 @@ module Locomotive
|
||||
Locomotive::Liquid::Drops::Site.new(self)
|
||||
end
|
||||
|
||||
def to_presenter(options = {})
|
||||
Locomotive::SitePresenter.new(self, options)
|
||||
end
|
||||
|
||||
def as_json(options = {})
|
||||
Locomotive::SitePresenter.new(self, options).as_json
|
||||
self.to_presenter(options).as_json
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -1,7 +1,7 @@
|
||||
module Locomotive
|
||||
class MembershipPresenter < BasePresenter
|
||||
|
||||
delegate :role, :to => :source
|
||||
delegate :role, :account_id, :to => :source
|
||||
|
||||
def name
|
||||
self.source.account.name
|
||||
@ -26,8 +26,13 @@ module Locomotive
|
||||
end
|
||||
|
||||
def included_methods
|
||||
super + %w(name email role role_name can_update grant_admin)
|
||||
super + %w(account_id name email role role_name can_update grant_admin)
|
||||
end
|
||||
|
||||
# def light_as_json
|
||||
# methods = included_methods.clone - %w(name email)
|
||||
# self.as_json(methods)
|
||||
# end
|
||||
|
||||
end
|
||||
end
|
@ -15,5 +15,10 @@ module Locomotive
|
||||
super + %w(name locales domain_name subdomain domains robots_txt seo_title meta_keywords meta_description domains_without_subdomain memberships)
|
||||
end
|
||||
|
||||
def as_json_for_html_view
|
||||
methods = included_methods.clone - %w(memberships)
|
||||
self.as_json(methods)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,10 +1,10 @@
|
||||
- if field.ui_enabled?
|
||||
- target_content_type = Locomotive::ContentType.class_name_to_content_type(field.class_name, current_site)
|
||||
|
||||
= f.input name.to_sym,
|
||||
:label => field.label,
|
||||
:hint => field.hint,
|
||||
:as => :'Locomotive::Empty',
|
||||
= f.input name.to_sym,
|
||||
:label => field.label,
|
||||
:hint => field.hint,
|
||||
:as => :'Locomotive::Empty',
|
||||
:wrapper_html => { :id => "content_entry_#{name}_input", :class => 'empty relationship input' }
|
||||
|
||||
- content_for :head do
|
||||
@ -38,4 +38,4 @@
|
||||
|
||||
- content_for :backbone_view_data do
|
||||
:plain
|
||||
, all_#{name}_entries: #{target_content_type.list_or_group_entries.to_json}
|
||||
, all_#{name}_entries: #{target_content_type.list_or_group_entries.to_json(:depth => 1)}
|
@ -19,7 +19,7 @@
|
||||
window.locale = '#{I18n.locale}';
|
||||
window.content_locale = '#{::Mongoid::Fields::I18n.locale}';
|
||||
|
||||
Locomotive.current_site = new Locomotive.Models.Site(#{current_site.to_json});
|
||||
Locomotive.current_site = new Locomotive.Models.Site(#{current_site.to_presenter.as_json_for_html_view.to_json});
|
||||
Locomotive.current_account = new Locomotive.Models.Account(#{current_locomotive_account.to_json});
|
||||
|
||||
$(document).ready(function() {
|
||||
|
@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
||||
|
||||
s.add_dependency 'mongo', '~> 1.5.2'
|
||||
s.add_dependency 'bson_ext', '~> 1.5.2'
|
||||
s.add_dependency 'mongoid', '~> 2.4.6'
|
||||
s.add_dependency 'mongoid', '~> 2.4.9'
|
||||
s.add_dependency 'locomotive-mongoid-tree', '~> 0.6.2'
|
||||
|
||||
s.add_dependency 'custom_fields', '~> 2.0.0.rc10'
|
||||
|
@ -10,11 +10,14 @@ defaults: &defaults
|
||||
development:
|
||||
<<: *defaults
|
||||
database: locomotive_engine_dev
|
||||
identity_map_enabled: true
|
||||
|
||||
test:
|
||||
<<: *defaults
|
||||
database: locomotive_engine_test
|
||||
identity_map_enabled: true
|
||||
|
||||
production:
|
||||
<<: *defaults
|
||||
identity_map_enabled: true
|
||||
database: locomotive_engine_production
|
||||
|
@ -131,7 +131,7 @@ describe Locomotive::ContentType do
|
||||
|
||||
it 'updates the information about the order of a has_many relationship if the target class changes its order' do
|
||||
@content_type.order_by = 'description'; @content_type.order_direction = 'ASC'; @content_type.save!
|
||||
@category_1 = @category_1.class.find(@category_1._id)
|
||||
@category_1 = safe_find(@category_1.class, @category_1._id)
|
||||
|
||||
@category_1.projects.metadata.order.should == %w(description ASC)
|
||||
@category_1.projects.map(&:name).should == %w(LocomotiveCMS RubyOnRails)
|
||||
@ -139,7 +139,9 @@ describe Locomotive::ContentType do
|
||||
|
||||
it 'uses the order by position if the UI option is enabled' do
|
||||
field = @category_content_type.entries_custom_fields.where(:name => 'projects').first
|
||||
field.ui_enabled = true; @category_content_type.save!; @category_1 = @category_1.class.find(@category_1._id)
|
||||
field.ui_enabled = true;
|
||||
|
||||
@category_content_type.save!; @category_1 = safe_find(@category_1.class, @category_1._id)
|
||||
|
||||
@category_1.projects.metadata.order.to_s.should == 'position_in_category'
|
||||
@category_1.projects.map(&:name).should == %w(LocomotiveCMS RubyOnRails)
|
||||
@ -337,6 +339,11 @@ describe Locomotive::ContentType do
|
||||
end
|
||||
end
|
||||
|
||||
def safe_find(klass, id)
|
||||
Mongoid::IdentityMap.clear
|
||||
klass.find(id)
|
||||
end
|
||||
|
||||
def build_content_entry(content_type)
|
||||
content_type.entries.build(:name => 'Asset on steroids', :description => 'Lorem ipsum', :active => true)
|
||||
end
|
||||
|
@ -143,8 +143,8 @@ describe Locomotive::Page do
|
||||
describe 'tree organization' do
|
||||
|
||||
before(:each) do
|
||||
@home = FactoryGirl.create(:page)
|
||||
@child_1 = FactoryGirl.create(:page, :title => 'Subpage 1', :slug => 'foo', :parent_id => @home._id, :site => @home.site)
|
||||
@home = FactoryGirl.create(:page)
|
||||
@child_1 = FactoryGirl.create(:page, :title => 'Subpage 1', :slug => 'foo', :parent_id => @home._id, :site => @home.site)
|
||||
end
|
||||
|
||||
it 'adds root elements' do
|
||||
@ -390,4 +390,5 @@ describe Locomotive::Page do
|
||||
def fake_bson_id(id)
|
||||
BSON::ObjectId(id.to_s.rjust(24, '0'))
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -27,6 +27,10 @@ RSpec.configure do |config|
|
||||
DatabaseCleaner.orm = 'mongoid'
|
||||
end
|
||||
|
||||
config.before(:each) do
|
||||
Mongoid::IdentityMap.clear
|
||||
end
|
||||
|
||||
config.before(:each) do
|
||||
DatabaseCleaner.clean
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user