From f9c68819e0c904f9d4292fd55f575ba7d9e28157 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Wed, 18 Apr 2018 12:52:37 +0100 Subject: Warn when Goldiloader's preloading exceeds 100 objects --- config/initializers/goldiloader.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 config/initializers/goldiloader.rb diff --git a/config/initializers/goldiloader.rb b/config/initializers/goldiloader.rb new file mode 100644 index 00000000000..2a5f9c9dbbc --- /dev/null +++ b/config/initializers/goldiloader.rb @@ -0,0 +1,25 @@ +module Goldiloader + module AssociationLoader + module LimitPreloading + PreloadingLimitExceeded = Class.new(StandardError) + + private + + def eager_load(models, association_name) + if Gitlab::Sentry.enabled? && models.count > 100 + Gitlab::Sentry.context + + Raven.capture_exception(PreloadingLimitExceeded.new("More than 100 models preloaded for #{models.first.class}.#{association_name}")) + return + end + + super + rescue => e + Raven.capture_exception(e) + end + end + + prepend LimitPreloading + singleton_class.prepend LimitPreloading + end +end -- cgit v1.2.1