Maintenance: Only load gems when they are needed to save memory otherwise.

This commit is contained in:
Martin Gruner 2021-07-05 13:38:40 +00:00
parent f37cf21092
commit 697661cbf2
18 changed files with 45 additions and 25 deletions

View file

@ -10,6 +10,4 @@ slack:
- when: on_success
script:
- bundle exec rake zammad:db:unseeded
- echo "gem 'slack-ruby-client'" >> Gemfile.local
- bundle install -j $(nproc)
- bundle exec rails test test/integration/slack_test.rb

21
Gemfile
View file

@ -45,7 +45,7 @@ gem 'pundit'
gem 'rszr', '0.5.2'
# performance - Memcached
gem 'dalli'
gem 'dalli', require: false
# asset handling - coffee-script
gem 'coffee-rails'
@ -95,7 +95,6 @@ gem 'omniauth-weibo-oauth2'
gem 'gmail_xoauth'
gem 'koala'
gem 'telegramAPI'
# Updating twitter to 'master' seems to break things, so freeze the revision for now.
gem 'twitter'
# channels - email additions
@ -112,7 +111,7 @@ gem 'biz'
gem 'diffy'
# feature - excel output
gem 'writeexcel'
gem 'writeexcel', require: false
# feature - device logging
gem 'browser'
@ -125,21 +124,20 @@ gem 'icalendar-recurrence'
gem 'telephone_number'
# feature - SMS
gem 'twilio-ruby'
gem 'twilio-ruby', require: false
# feature - ordering
gem 'acts_as_list'
# integrations
gem 'clearbit'
gem 'clearbit', require: false
gem 'net-ldap'
gem 'slack-notifier'
gem 'zendesk_api'
gem 'slack-notifier', require: false
gem 'zendesk_api', require: false
# integrations - exchange
gem 'autodiscover', git: 'https://github.com/zammad-deps/autodiscover'
gem 'rubyntlm', git: 'https://github.com/wimm/rubyntlm'
gem 'viewpoint'
gem 'autodiscover', git: 'https://github.com/zammad-deps/autodiscover', require: false
gem 'viewpoint', require: false
# integrations - S/MIME
gem 'openssl'
@ -218,6 +216,9 @@ group :development, :test do
# refresh ENVs in CI environment
gem 'dotenv', require: false
# Slack helper for testing
gem 'slack-ruby-client', require: false
end
# Want to extend Zammad with additional gems?

View file

@ -1,9 +1,3 @@
GIT
remote: https://github.com/wimm/rubyntlm
revision: 53969639b87b9e5d5fef560f19cf0d977259591c
specs:
rubyntlm (0.1.2)
GIT
remote: https://github.com/zammad-deps/autodiscover
revision: ee9b53dfa797ce6d4f970b82beea7fbdd2df56bb
@ -228,6 +222,8 @@ GEM
faraday (>= 0.8)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.1.0)
faraday_middleware (1.0.0)
faraday (~> 1.0)
ffi (1.15.3)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
@ -243,6 +239,7 @@ GEM
octokit (~> 4.6)
rainbow (>= 2.2.1)
rake (>= 10.0)
gli (2.20.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
gmail_xoauth (0.4.2)
@ -525,6 +522,7 @@ GEM
nokogiri (>= 1.10.5)
rexml
ruby2_keywords (0.0.4)
rubyntlm (0.6.3)
rubyzip (2.3.0)
sassc (2.4.0)
ffi (~> 1.9)
@ -553,6 +551,12 @@ GEM
simplecov (>= 0.4.1)
simplecov_json_formatter (0.1.3)
slack-notifier (2.4.0)
slack-ruby-client (0.17.0)
faraday (>= 1.0)
faraday_middleware
gli
hashie
websocket-driver
slop (3.6.0)
spring (2.1.1)
spring-commands-rspec (1.0.4)
@ -721,13 +725,13 @@ DEPENDENCIES
rubocop-performance
rubocop-rails
rubocop-rspec
rubyntlm!
sassc-rails
selenium-webdriver
shoulda-matchers
simplecov
simplecov-rcov
slack-notifier
slack-ruby-client
spring
spring-commands-rspec
spring-commands-testunit

View file

@ -7,6 +7,7 @@ class Integration::ExchangeController < ApplicationController
def autodiscover
answer_with do
require 'autodiscover' # Only load this gem when it is really used.
client = Autodiscover::Client.new(
email: params[:user],
password: params[:password],

View file

@ -142,6 +142,7 @@ class Channel::Driver::Sms::Twilio
private
def api(options)
require 'twilio-ruby' # Only load this gem when it is really used.
@api ||= ::Twilio::REST::Client.new options[:account_id], options[:token]
end
end

View file

@ -168,6 +168,7 @@ class Transaction::Slack
Rails.logger.debug { "sent webhook (#{@item[:type]}/#{ticket.id}/#{local_config['webhook']})" }
require 'slack-notifier' # Only load this gem when it is really used.
notifier = Slack::Notifier.new(
local_config['webhook'],
channel: local_config['channel'],

View file

@ -47,11 +47,12 @@ module Zammad
config.api_path = '/api/v1'
# define cache store
config.cache_store = if ENV['MEMCACHE_SERVERS'].present?
[:mem_cache_store, ENV['MEMCACHE_SERVERS'], { expires_in: 7.days }]
else
[:zammad_file_store, Rails.root.join('tmp', "cache_file_store_#{Rails.env}"), { expires_in: 7.days }]
end
if ENV['MEMCACHE_SERVERS'].present?
require 'dalli' # Only load this gem when it is really used.
config.cache_store = [:mem_cache_store, ENV['MEMCACHE_SERVERS'], { expires_in: 7.days }]
else
config.cache_store = [:zammad_file_store, Rails.root.join('tmp', "cache_file_store_#{Rails.env}"), { expires_in: 7.days }]
end
# define websocket session store
config.websocket_session_store = if ENV['REDIS_URL'].present?

View file

@ -148,6 +148,7 @@ module Enrichment
}
begin
require 'clearbit' # Only load this gem when it is really used.
::Clearbit.key = @config['api_key']
result = ::Clearbit::Enrichment.find(email: @local_user.email, stream: true)
record[:response] = { code: 200, content: result.to_s }

View file

@ -3,6 +3,9 @@
class ExcelSheet
def initialize(title:, header:, records:, locale:, timezone: nil)
require 'writeexcel' # Only load this gem when it is really used.
@title = title
@header = header
@records = records

View file

@ -11,6 +11,7 @@ class Sequencer
private
def ews_connection
require 'viewpoint' # Only load this gem when it is really used.
Viewpoint::EWSClient.new(
config[:endpoint],
config[:user],

View file

@ -15,6 +15,7 @@ class Sequencer
end
def resource_collection
require 'zendesk_api' # Only load this gem when it is really used.
@resource_collection ||= "::ZendeskAPI::#{resource_klass}".constantize.incremental_export(client, 1)
end

View file

@ -27,6 +27,7 @@ class Sequencer
# that it returns max. 1000. That's why we need to update the total
# number while importing in the resource loop
def request(object)
require 'zendesk_api' # Only load this gem when it is really used.
resource_class = "::ZendeskAPI::#{object.to_s.singularize}".safe_constantize
if resource_class.respond_to?(:incremental_export)
# read as: ::ZendeskAPI::Ticket.incremental_export(client, 1)

View file

@ -10,6 +10,7 @@ class Sequencer
private
def client
require 'zendesk_api' # Only load this gem when it is really used.
ZendeskAPI::Client.new do |config|
config.url = Setting.get('import_zendesk_endpoint')

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'rails_helper'
require 'autodiscover' # Only load this gem when it is really used.
RSpec.describe 'Exchange integration endpoint', type: :request do
before { authenticated_as(admin_with_admin_user_permissions) }

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'rails_helper'
require 'viewpoint' # Only load this gem when it is really used.
RSpec.describe Import::Exchange::Folder do
# see https://github.com/zammad/zammad/issues/2152

View file

@ -1,5 +1,7 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'zendesk_api' # Only load this gem when it is really used.
RSpec.shared_examples 'Sequencer::Unit::Import::Zendesk::SubSequence::Base' do
describe 'error handling' do
before do

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'rails_helper'
require 'autodiscover' # Only load this gem when it is really used.
RSpec.describe 'Exchange integration endpoint', type: :request do
before { authenticated_as(admin_with_admin_user_permissions) }

View file

@ -1,7 +1,7 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'integration_test_helper'
require 'slack'
require 'slack-ruby-client' # Only load this gem when it is really used.
class SlackTest < ActiveSupport::TestCase