From 49927728cd1d6f6985dd578f6df45e767f6c0027 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 6 Jul 2012 17:31:18 +0400 Subject: [PATCH] [issue #428] Fetching packages moved to particular method. --- app/controllers/advisories_controller.rb | 26 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/app/controllers/advisories_controller.rb b/app/controllers/advisories_controller.rb index ee1adf6f2..6923cd878 100644 --- a/app/controllers/advisories_controller.rb +++ b/app/controllers/advisories_controller.rb @@ -5,6 +5,8 @@ class AdvisoriesController < ApplicationController load_resource :find_by => :advisory_id authorize_resource + before_filter :fetch_packages_info + def index @advisories = @advisories.scoped(:include => :platforms) @advisories = @advisories.search_by_id(params[:q]) if params[:q] @@ -16,7 +18,21 @@ class AdvisoriesController < ApplicationController end def show - @packages_info = Hash.new { |h, k| h[k] = {} } + end + + def search + @advisory = Advisory.by_update_type(params[:bl_type]).search_by_id(params[:query]).first + raise ActionController::RoutingError.new('Not Found') if @advisory.nil? + respond_to do |format| + format.json { render @advisory } + end + end + + protected + + # this method fetches and structurize packages attached to current advisory. + def fetch_packages_info + @packages_info = Hash.new { |h, k| h[k] = {} } # maaagic, it's maaagic ;) @advisory.build_lists.find_in_batches(:include => [:save_to_platform, :packages, :project]) do |batch| batch.each do |build_list| tmp = build_list.packages.inject({:srpm => nil, :rpm => []}) do |h, p| @@ -31,12 +47,4 @@ class AdvisoriesController < ApplicationController end end - def search - @advisory = Advisory.by_update_type(params[:bl_type]).search_by_id(params[:query]).first - raise ActionController::RoutingError.new('Not Found') if @advisory.nil? - respond_to do |format| - format.json { render @advisory } - end - end - end