Ver código fonte

Reduce the rate at which PopulateGrid is called to prevent the UI from grinding to a halt.

Brett Credo 8 anos atrás
pai
commit
02ce6b4a85
1 arquivos alterados com 18 adições e 2 exclusões
  1. 18 2
      BulkPrinting/BulkPrinting/BatchDownloader.cs

+ 18 - 2
BulkPrinting/BulkPrinting/BatchDownloader.cs

@@ -90,6 +90,7 @@ namespace BulkPrinting
90 90
                         Log.Error(e, "Error while downloading batch list");
91 91
                     }
92 92
 
93
+                    // TODO: throttle or detect changes better
93 94
                     if (!isCancelled && doRefresh)
94 95
                     {
95 96
                         doRefresh = false;
@@ -100,19 +101,23 @@ namespace BulkPrinting
100 101
                     try
101 102
                     {
102 103
                         using (var command = _db.CreateCommand(
103
-                            "SELECT Id FROM Batch WHERE Downloaded=0 ORDER BY Downloaded, Id"))
104
+                            "SELECT Id, ReadyForDownload FROM Batch WHERE Downloaded=0 ORDER BY Downloaded, Id"))
104 105
                         {
105 106
                             using (SQLiteDataReader row = command.ExecuteReader())
106 107
                             {
107 108
                                 while (! isCancelled && row.Read())
108 109
                                 {
109 110
                                     int batchId = (int)row["Id"];
111
+                                    bool oldReadyForDownload = (bool)row["ReadyForDownload"];
110 112
                                     try
111 113
                                     {
112 114
                                         Batch batch = new Batch();
113 115
                                         if (Utility.RESTRequest(ref batch, String.Format("/api/batches/{0}", batchId)))
114 116
                                         {
115
-                                            doRefresh = true;
117
+                                            if (batch.ReadyForDownload != oldReadyForDownload)
118
+                                            {
119
+                                                doRefresh = true;
120
+                                            }
116 121
                                             Utility.SaveBatch(_db, batch);
117 122
 
118 123
                                             if (batch.ReadyForDownload)
@@ -193,6 +198,8 @@ namespace BulkPrinting
193 198
                                                     _db.ExecuteNonQuery(
194 199
                                                         "UPDATE Batch SET Downloaded=1 WHERE Id=@BatchId",
195 200
                                                         new SQLiteParameter("@BatchId", batchId));
201
+
202
+                                                    doRefresh = true;
196 203
                                                 }
197 204
                                             }
198 205
                                         }
@@ -218,11 +225,13 @@ namespace BulkPrinting
218 225
                                         Log.Error(e, "Error while downloading vouchers for batch {0}", batchId);
219 226
                                     }
220 227
 
228
+                                    /* TODO: throttle or detect changes better
221 229
                                     if (!isCancelled && doRefresh)
222 230
                                     {
223 231
                                         doRefresh = false;
224 232
                                         _refreshAction();
225 233
                                     }
234
+                                    */
226 235
 
227 236
                                     lock(_lock)
228 237
                                     {
@@ -236,6 +245,13 @@ namespace BulkPrinting
236 245
                     {
237 246
                         Log.Error(e, "Error while downloading vouchers");
238 247
                     }
248
+
249
+                    // TODO: throttle or detect changes better
250
+                    if (!isCancelled && doRefresh)
251
+                    {
252
+                        doRefresh = false;
253
+                        _refreshAction();
254
+                    }
239 255
                 }
240 256
                 else
241 257
                 {