Changeset 1707

Show
Ignore:
Timestamp:
07/19/08 21:18:20 (1 month ago)
Author:
kindlund
Message:

Performance improvement: Rather than have the drone database query for 'distinct' status fields, we have it query the smaller Configurations table for unique status fields. This dramatically improves the UI responsiveness and DB performance.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • hive/trunk/data_webapp/app/helpers/clients_helper.rb

    r1701 r1707  
    4242    klass = instance.class 
    4343    klass_name = klass.table_name.singularize 
    44     @statuses = klass.find(:all,:select=>"DISTINCT(status)").map(&:status).to_a 
     44    @statuses = Configuration.get_all(:name => 'status', :namespace => klass.to_s) 
    4545    if not @statuses.nil? 
    4646      out += render :controller => klass_name, :partial => 'status_chooser', 
  • hive/trunk/data_webapp/app/models/configuration.rb

    r1574 r1707  
    11class Configuration < ActiveRecord::Base 
    22 
    3   # Get accepts two required arguments: 
     3  # get accepts two required arguments: 
    44  #  
    55  # * <tt>:name</tt>: The name of the variable to look for. 
     
    77  # 
    88  # If any configuration entry contains a matching name and 
    9   # namespace, then the corresponding value is returned. 
     9  # namespace, then the corresponding value of the first 
     10  # match is returned. 
    1011  # 
    1112  # Otherwise, nil will be returned. 
     
    1415    return obj.nil? ? nil : obj.value 
    1516  end 
     17   
     18  # get_all accepts two required arguments: 
     19  #  
     20  # * <tt>:name</tt>: The name of the variable to look for. 
     21  # * <tt>:namespace</tt>: The namespace to search within. 
     22  # 
     23  # If any configuration entry contains a matching name and 
     24  # namespace, then the corresponding values will be returned 
     25  # in an array. 
     26  # 
     27  # Otherwise, an empty array will be returned. 
     28  def self.get_all(args = {}) 
     29    return Configuration.find(:all, :conditions => args).map(&:value).to_a 
     30  end 
    1631 
    1732end 
  • hive/trunk/data_webapp/app/views/clients/index.html.erb

    r1501 r1707  
    11<h2>Client data</h2> 
    22      View Clients of type: 
    3       <%= select(:client,:status,Client.find(:all,:select=>"DISTINCT(status)").map(&:status).to_a,{:include_blank => true},{:onchange => remote_function(:url => clients_url, :method => 'get',:with => "'status='+this.value")}) %> 
     3      <%= select(:client,:status,Configuration.get_all(:name => 'status', :namespace => 'Client'),{:include_blank => true},{:onchange => remote_function(:url => clients_url, :method => 'get',:with => "'status='+this.value")}) %> 
    44      <p/> 
    55      <div id="data">