Skip to content
Browse files

Eliminate an unnecessary query from the webhook firing process

  • Loading branch information...
1 parent bc22c83 commit a7d06bd426dc1934f608e81a12e291af7e9a8889 @laserlemon laserlemon committed Nov 21, 2011
Showing with 8 additions and 5 deletions.
  1. +2 −2 app/controllers/api/v1/rubygems_controller.rb
  2. +2 −3 app/models/pusher.rb
  3. +4 −0 app/models/web_hook.rb
View
4 app/controllers/api/v1/rubygems_controller.rb
@@ -31,7 +31,7 @@ def create
def yank
if @version.indexed?
@rubygem.yank!(@version)
- (@rubygem.web_hooks + WebHook.global).each do |web_hook|
+ WebHook.for_rubygem(@rubygem).each do |web_hook|
web_hook.fire("yank", request.host_with_port, @rubygem, @version, true)
end
render :text => "Successfully yanked gem: #{@version.to_title}"
@@ -43,7 +43,7 @@ def yank
def unyank
if !@version.indexed?
@version.unyank!
- (@rubygem.web_hooks + WebHook.global).each do |web_hook|
+ WebHook.for_rubygem(@rubygem).each do |web_hook|
web_hook.fire("unyank", request.host_with_port, @rubygem, @version, true)
end
render :text => "Successfully unyanked gem: #{@version.to_title}"
View
5 app/models/pusher.rb
@@ -89,9 +89,8 @@ def inspect
end
def enqueue_web_hook_jobs
- jobs = rubygem.web_hooks + WebHook.global
- jobs.each do |job|
- job.fire("push", @host_with_port, rubygem, version)
+ WebHook.for_rubygem(rubygem).each do |web_hook|
+ web_hook.fire("push", @host_with_port, rubygem, version)
end
end
end
View
4 app/models/web_hook.rb
@@ -15,6 +15,10 @@ def self.specific
where("rubygem_id is not null")
end
+ def self.for_rubygem(rubygem)
+ where("rubygem_id = ? or rubygem_id is null", rubygem.id)
+ end
+
def fire(event, host_with_port, deploy_gem, version, delayed=true)
job = Notifier.new(event, url, host_with_port, deploy_gem, version, user.api_key)
if delayed

0 comments on commit a7d06bd

Please sign in to comment.
Something went wrong with that request. Please try again.