Commit 17823fb44e036445ed31a957f8ba02ae03b95f43
1 parent
8c31af4c
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Improve register performance
Showing
1 changed file
with
5 additions
and
6 deletions
Show diff stats
app/models/profile.rb
... | ... | @@ -356,7 +356,7 @@ class Profile < ActiveRecord::Base |
356 | 356 | end |
357 | 357 | |
358 | 358 | # registar callback for creating boxes after the object is created. |
359 | - after_create :create_default_set_of_boxes | |
359 | + before_create :create_default_set_of_boxes | |
360 | 360 | |
361 | 361 | # creates the initial set of boxes when the profile is created. Can be |
362 | 362 | # overriden for each subclass to create a custom set of boxes for its |
... | ... | @@ -422,9 +422,6 @@ class Profile < ActiveRecord::Base |
422 | 422 | self.custom_footer = template[:custom_footer] |
423 | 423 | self.custom_header = template[:custom_header] |
424 | 424 | self.public_profile = template.public_profile |
425 | - | |
426 | - # flush | |
427 | - self.save(:validate => false) | |
428 | 425 | end |
429 | 426 | |
430 | 427 | def apply_type_specific_template(template) |
... | ... | @@ -613,15 +610,15 @@ private :generate_url, :url_options |
613 | 610 | after_create :insert_default_article_set |
614 | 611 | def insert_default_article_set |
615 | 612 | if template |
616 | - copy_articles_from template | |
613 | + self.save! if copy_articles_from template | |
617 | 614 | else |
618 | 615 | default_set_of_articles.each do |article| |
619 | 616 | article.profile = self |
620 | 617 | article.advertise = false |
621 | 618 | article.save! |
622 | 619 | end |
620 | + self.save! | |
623 | 621 | end |
624 | - self.save! | |
625 | 622 | end |
626 | 623 | |
627 | 624 | # Override this method in subclasses of Profile to create a default article |
... | ... | @@ -642,10 +639,12 @@ private :generate_url, :url_options |
642 | 639 | end |
643 | 640 | |
644 | 641 | def copy_articles_from other |
642 | + return false if other.top_level_articles.empty? | |
645 | 643 | other.top_level_articles.each do |a| |
646 | 644 | copy_article_tree a |
647 | 645 | end |
648 | 646 | self.articles.reload |
647 | + true | |
649 | 648 | end |
650 | 649 | |
651 | 650 | def copy_article_tree(article, parent=nil) | ... | ... |