total.rb 863 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Ldap::Users::Total < Sequencer::Unit::Base
  3. include ::Sequencer::Unit::Import::Common::Model::Statistics::Mixin::EmptyDiff
  4. uses :ldap_config, :ldap_connection, :dry_run
  5. def process
  6. state.provide(:statistics_diff) do
  7. diff.merge(
  8. total: ((diff[:total] || 0) + total)
  9. )
  10. end
  11. end
  12. private
  13. def total
  14. if !dry_run
  15. result = Rails.cache.read(cache_key)
  16. end
  17. result ||= ldap_connection.count(ldap_config[:user_filter])
  18. if !dry_run
  19. Rails.cache.write(cache_key, result, { expires_in: 1.hour })
  20. end
  21. result
  22. end
  23. def cache_key
  24. @cache_key ||= "#{ldap_connection.host}::#{ldap_connection.port}::#{ldap_config[:ssl]}::#{ldap_connection.base_dn}::#{ldap_config[:user_filter]}"
  25. end
  26. end