myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2402] trunk: cached ratings in the contributions


From: noreply
Subject: [myexperiment-hackers] [2402] trunk: cached ratings in the contributions table for easier sorting
Date: Wed, 12 May 2010 11:31:30 -0400 (EDT)

Revision
2402
Author
dgc
Date
2010-05-12 11:31:29 -0400 (Wed, 12 May 2010)

Log Message

cached ratings in the contributions table for easier sorting

Modified Paths

Diff

Modified: trunk/app/controllers/blobs_controller.rb (2401 => 2402)


--- trunk/app/controllers/blobs_controller.rb	2010-05-12 14:51:20 UTC (rev 2401)
+++ trunk/app/controllers/blobs_controller.rb	2010-05-12 15:31:29 UTC (rev 2402)
@@ -238,7 +238,7 @@
     else
       Rating.delete_all(["rateable_type = ? AND rateable_id = ? AND user_id = ?", @blob.class.to_s, @blob.id, current_user.id])
       
-      @blob.ratings << Rating.create(:user => current_user, :rating => params[:rating])
+      Rating.create(:rateable => @blob, :user => current_user, :rating => params[:rating])
       
       respond_to do |format|
         format.html { 

Modified: trunk/app/controllers/workflows_controller.rb (2401 => 2402)


--- trunk/app/controllers/workflows_controller.rb	2010-05-12 14:51:20 UTC (rev 2401)
+++ trunk/app/controllers/workflows_controller.rb	2010-05-12 15:31:29 UTC (rev 2402)
@@ -119,7 +119,7 @@
     else
       Rating.delete_all(["rateable_type = ? AND rateable_id = ? AND user_id = ?", @workflow.class.to_s, @workflow.id, current_user.id])
       
-      @workflow.ratings << Rating.create(:user => current_user, :rating => params[:rating])
+      Rating.create(:rateable => @workflow, :user => current_user, :rating => params[:rating])
       
       respond_to do |format|
         format.html { 

Modified: trunk/app/models/rating.rb (2401 => 2402)


--- trunk/app/models/rating.rb	2010-05-12 14:51:20 UTC (rev 2401)
+++ trunk/app/models/rating.rb	2010-05-12 15:31:29 UTC (rev 2402)
@@ -6,6 +6,9 @@
 class Rating < ActiveRecord::Base
   belongs_to :rateable, :polymorphic => true
   
+  after_save    :update_contribution_rating
+  after_destroy :update_contribution_rating
+      
   # NOTE: Comments belong to a user
   belongs_to :user
   
@@ -17,4 +20,13 @@
       :order => "created_at DESC"
     )
   end
+
+  private
+
+  def update_contribution_rating
+    if rateable.contribution
+      rateable.contribution.update_attribute(:rating, rateable.rating)
+    end
+  end
 end
+

Modified: trunk/config/base_schema.xml (2401 => 2402)


--- trunk/config/base_schema.xml	2010-05-12 14:51:20 UTC (rev 2401)
+++ trunk/config/base_schema.xml	2010-05-12 15:31:29 UTC (rev 2402)
@@ -1,6 +1,21 @@
 <?xml version="1.0"?>
 <schema>
 
+  <table name="contributions">
+
+    <column type="integer"  name="contributor_id"/>
+    <column type="string"   name="contributor_type"/>
+    <column type="integer"  name="contributable_id"/>
+    <column type="string"   name="contributable_type"/>
+    <column type="integer"  name="policy_id"/>
+    <column type="datetime" name="created_at"/>
+    <column type="datetime" name="updated_at"/>
+    <column type="integer"  name="downloads_count"/>
+    <column type="integer"  name="viewings_count"/>
+    <column type="float"    name="rating"/>
+
+  </table>
+
   <table name="content_types">
 
     <column type="integer"  name="user_id"/>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]