From 637c474f4ef41cb53f448777362fc42b5bbddf8f Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 1 Nov 2016 15:24:07 +0800 Subject: [PATCH] PERF: Don't build wizard until we actually load the wizard. --- lib/wizard.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/wizard.rb b/lib/wizard.rb index 2e1689c5b62..ab6c5c33c02 100644 --- a/lib/wizard.rb +++ b/lib/wizard.rb @@ -82,11 +82,15 @@ class Wizard .where.not(auth_token_updated_at: nil) .order(:auth_token_updated_at) - @user.present? && first_admin.first == @user && !completed? && (Topic.count < 15) + if @user.present? && first_admin.first == @user && (Topic.count < 15) + !Wizard::Builder.new(@user).build.completed? + else + false + end end def self.user_requires_completion?(user) - Wizard::Builder.new(user).build.requires_completion? + self.new(user).requires_completion? end end