New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Changeset 80844


Ignore:
Timestamp:
07/18/11 15:37:51 (4 years ago)
Author:
derek@…
Message:

Changes to way existing records are queried

add_os_data

  • Use User association to get an existing OsStatistics entry. This should be clearer and easier to read than before.

add_port

  • Finding an existing InstalledPort now also uses the user association.
  • Check if :created_at falls between the range [start_of_month, end_of_month] rather than use month,year columns
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gsoc11-statistics/stats-server/app/models/submission.rb

    r80746 r80844  
    1818    
    1919    # Try to find an existing entry 
    20     os_stats = OsStatistic.find_by_user_id(user.id) 
     20    os_stats = user.os_statistic 
    2121      
    2222    if os_stats.nil? 
     
    4343    logger.debug {"Adding installed port #{installed_port['name']}"} 
    4444     
    45     # Update any ports found for this user is they have already been submitted this month 
    46     port_entry = InstalledPort.find_by_port_id_and_user_id_and_month_and_year(macports_port.id,  
    47                                                                               user.id,  
    48                                                                               month,  
    49                                                                               year) 
    50      
    51     # New port entry                   
     45    # Update any ports found for this user if they have already been submitted this month   
     46    port_entrys = user.installed_ports.where(:created_at => (Date.today.at_beginning_of_month)..(Date.today.at_end_of_month)) 
     47    port_entry = port_entrys.find_by_port_id(macports_port.id) 
     48 
     49    # No existing entry was found - create a new one                 
    5250    if port_entry.nil? 
    5351      port_entry = InstalledPort.new 
    5452    end 
    55          
     53     
    5654    port_entry[:user_id]  = user.id 
    5755    port_entry[:port_id]  = macports_port.id 
    5856    port_entry[:version]  = installed_port['version'] 
    5957    port_entry[:variants] = installed_port['variants'] 
    60     port_entry[:month]    = month 
    61     port_entry[:year]     = year 
    62                                
     58                             
    6359    if not port_entry.save 
    6460     logger.debug "Unable to save port #{installed_port['name']}" 
Note: See TracChangeset for help on using the changeset viewer.