myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2014] branches/invitation_throttling/app/control


From: noreply
Subject: [myexperiment-hackers] [2014] branches/invitation_throttling/app/controllers/application.rb: Throttling.
Date: Fri, 28 Nov 2008 12:10:16 -0500 (EST)

Revision
2014
Author
alekses6
Date
2008-11-28 12:10:15 -0500 (Fri, 28 Nov 2008)

Log Message

Throttling. Performance improvement - saving of the limit entry now will be made only if changes to it were made (sometimes the method is executed for "probing" purposes only, with no changes - even with counter not incremented).

Modified Paths

Diff

Modified: branches/invitation_throttling/app/controllers/application.rb (2013 => 2014)


--- branches/invitation_throttling/app/controllers/application.rb	2008-11-28 15:46:16 UTC (rev 2013)
+++ branches/invitation_throttling/app/controllers/application.rb	2008-11-28 17:10:15 UTC (rev 2014)
@@ -43,6 +43,7 @@
   # limited allowance of usage (e.g. 5 messages a day, etc)
   def check_activity_limit(contributor, limit_feature, update_counter=true)
     time_now = Time.now
+    limit_save_required = false
     
     if (limit = ActivityLimit.find(:first, :conditions => ["contributor_type = ? AND contributor_id = ? AND limit_feature = ?", contributor.class.name, contributor.id, limit_feature]))
       # limit exists - check its validity
@@ -51,7 +52,8 @@
         # now it's the time to reset the counter to zero - no matter what its value was before
         # (this will never be executed for non-periodic counters)
         limit.current_count = 0
-        limit.reset_after = time_now + limit.limit_frequency.hours        
+        limit.reset_after = time_now + limit.limit_frequency.hours
+        limit_save_required = true
 
         # also check if the contributor needs to be "promoted" to the next level --
         # e.g. in the first month of membership on myExperiment one can send 10 messages daily,
@@ -105,6 +107,8 @@
                                 :reset_after => (limit_frequency ? (time_now + limit_frequency.hours) : nil),
                                 :promote_after => (promote_every ? (time_now + promote_every.days) : nil),
                                 :current_count => 0)
+                                
+      limit_save_required = true
     end
     
     
@@ -119,8 +123,9 @@
     # update counter for the "current" action
     if action_allowed && update_counter
       limit.current_count += 1
+      limit_save_required = true
     end
-    limit.save # saves all changes (including counter resets, etc)
+    limit.save if limit_save_required # saves all changes (including counter resets, etc) if any were made
     
     # return if action is allowed / denied and when the next reset is going to be (nil for non-periodic counters) 
     return [action_allowed, (limit.reset_after ? (limit.reset_after - time_now) : nil)]

reply via email to

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