Skip to content

Commit

Permalink
Maintenance: Only load gems when they are needed to save memory other…
Browse files Browse the repository at this point in the history
…wise.
  • Loading branch information
mgruner committed Jul 5, 2021
1 parent f37cf21 commit 697661c
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 25 deletions.
2 changes: 0 additions & 2 deletions .gitlab/ci/integration/slack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 11 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -112,7 +111,7 @@ gem 'biz'
gem 'diffy'

# feature - excel output
gem 'writeexcel'
gem 'writeexcel', require: false

# feature - device logging
gem 'browser'
Expand All @@ -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'
Expand Down Expand Up @@ -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?
Expand Down
18 changes: 11 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/controllers/integration/exchange_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions app/models/channel/driver/sms/twilio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def self.definition
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
1 change: 1 addition & 0 deletions app/models/transaction/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def perform

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'],
Expand Down
11 changes: 6 additions & 5 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ class Application < Rails::Application
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?
Expand Down
1 change: 1 addition & 0 deletions lib/enrichment/clearbit/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def fetch
}

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 }
Expand Down
3 changes: 3 additions & 0 deletions lib/excel_sheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/sequencer/unit/exchange/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Connection < Sequencer::Unit::Common::Provider::Fallback
private

def ews_connection
require 'viewpoint' # Only load this gem when it is really used.
Viewpoint::EWSClient.new(
config[:endpoint],
config[:user],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def self.included(base)
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

Expand Down
1 change: 1 addition & 0 deletions lib/sequencer/unit/import/zendesk/objects_total_count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def statistics_diff
# 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)
Expand Down
1 change: 1 addition & 0 deletions lib/sequencer/unit/zendesk/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Client < Sequencer::Unit::Common::Provider::Fallback
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')

Expand Down
1 change: 1 addition & 0 deletions spec/controllers/integration/exchange_spec.rb
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down
1 change: 1 addition & 0 deletions spec/lib/import/exchange/folder_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/requests/integration/exchange_spec.rb
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down
2 changes: 1 addition & 1 deletion test/integration/slack_test.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 697661c

Please sign in to comment.