tasque r180 - in trunk: . RtmNet



Author: sharm
Date: Tue Dec 23 16:30:22 2008
New Revision: 180
URL: http://svn.gnome.org/viewvc/tasque?rev=180&view=rev

Log:
* tasque/RtmNet/Rtm.cs: Limit API requests to no more than one per
  second. Last fix for bug #562026. Adds some noticeable slowdown to
  certain actions (like refreshing tasks and creating tasks), but it is
  necessary. A better fix will be to store all tasks in a sqlite db
  that periodically syncs with the backend without interrupting the
  user.

Modified:
   trunk/ChangeLog
   trunk/RtmNet/Rtm.cs

Modified: trunk/RtmNet/Rtm.cs
==============================================================================
--- trunk/RtmNet/Rtm.cs	(original)
+++ trunk/RtmNet/Rtm.cs	Tue Dec 23 16:30:22 2008
@@ -35,6 +35,7 @@
 		private const string UserAgent = "Mozilla/4.0 RtmNet API (compatible; MSIE 6.0; Windows NT 5.1)";
 		private string lastRequest;
 		private string lastResponse;
+		private DateTime lastRequestTime;
 
 		private WebProxy proxy;// = WebProxy.GetDefaultProxy();
 
@@ -208,6 +209,11 @@
 		/// then they are sent as part of the body instead.</remarks>
 		private string DoGetResponse(string url, string variables)
 		{
+			// Enforce no more than one request per second
+			TimeSpan timeDiff = DateTime.Now - lastRequestTime;
+			if (timeDiff.TotalMilliseconds < 1000 && timeDiff.TotalMilliseconds > 0)
+				System.Threading.Thread.Sleep (1000 - (int)timeDiff.TotalMilliseconds);
+			
 			HttpWebRequest req = null;
 			HttpWebResponse res = null;
 
@@ -257,6 +263,7 @@
 			try
 			{
 				// Get response from the internet
+				lastRequestTime = DateTime.Now;
 				res = (HttpWebResponse)req.GetResponse();
 			}
 			catch(WebException ex)



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