DEV: call 'enqueue_hooks' method only if active webhooks exist

DEV: call ‘enqueue_hooks’ method only if active webhooks exist

diff --git a/app/models/concerns/has_destroyed_web_hook.rb b/app/models/concerns/has_destroyed_web_hook.rb
index 081189f..233a808 100644
--- a/app/models/concerns/has_destroyed_web_hook.rb
+++ b/app/models/concerns/has_destroyed_web_hook.rb
@@ -7,11 +7,16 @@ module HasDestroyedWebHook
 
   def enqueue_destroyed_web_hook
     type = self.class.name.underscore.to_sym
-    payload = WebHook.generate_payload(type, self) if WebHook.active_web_hooks(type).exists?
-    yield
-    WebHook.enqueue_hooks(type, "#{type}_destroyed".to_sym,
-      id: id,
-      payload: payload
-    )
+
+    if WebHook.active_web_hooks(type).exists?
+      payload = WebHook.generate_payload(type, self)
+      yield
+      WebHook.enqueue_hooks(type, "#{type}_destroyed".to_sym,
+        id: id,
+        payload: payload
+      )
+    else
+      yield
+    end
   end
 end

GitHub sha: 27e7f2be

1 Like