Browse Source

Maintenance: Improve performance of 2FA backend.

Florian Liebe 1 year ago
parent
commit
7911ca2b34
2 changed files with 6 additions and 2 deletions
  1. 1 1
      app/graphql/gql/types/enum/two_factor_method_type.rb
  2. 5 1
      lib/auth/two_factor.rb

+ 1 - 1
app/graphql/gql/types/enum/two_factor_method_type.rb

@@ -4,7 +4,7 @@ module Gql::Types::Enum
   class TwoFactorMethodType < BaseEnum
     description 'Possible two factor authentication methods (availability depends on system configuration)'
 
-    Auth::TwoFactor::Method.descendants.each do |method|
+    Auth::TwoFactor.method_classes.each do |method|
       instance = method.new
       value instance.method_name, instance.method_name(human: true)
     end

+ 5 - 1
lib/auth/two_factor.rb

@@ -4,10 +4,14 @@ class Auth::TwoFactor
 
   attr_reader :user, :all_methods
 
+  def self.method_classes
+    @method_classes ||= Auth::TwoFactor::Method.descendants
+  end
+
   def initialize(user)
     @user = user
 
-    @all_methods = Auth::TwoFactor::Method.descendants.map { |method| method.new(user) }
+    @all_methods = self.class.method_classes.map { |method| method.new(user) }
   end
 
   def enabled?