]>
Commit | Line | Data |
---|---|---|
c45bc501 DM |
1 | // Serialize load (avoid too many parallel connections) |
2 | Ext.define('PVE.data.UpdateQueue', { | |
3 | singleton: true, | |
4 | ||
5 | constructor : function(){ | |
6 | var me = this; | |
7 | ||
8 | var queue = []; | |
9 | var queue_idx = {}; | |
10 | ||
11 | var idle = true; | |
12 | ||
13 | var start_update = function() { | |
14 | if (!idle) { | |
15 | return; | |
16 | } | |
17 | ||
18 | var storeid = queue.shift(); | |
19 | if (!storeid) { | |
20 | return; | |
21 | } | |
22 | var info = queue_idx[storeid]; | |
23 | queue_idx[storeid] = null; | |
24 | ||
25 | info.updatestart = new Date(); | |
26 | ||
27 | idle = false; | |
28 | info.store.load({ | |
29 | callback: function(records, operation, success) { | |
30 | idle = true; | |
31 | if (info.callback) { | |
32 | var runtime = (new Date()).getTime() - info.updatestart.getTime(); | |
33 | info.callback(runtime, success); | |
34 | } | |
35 | start_update(); | |
36 | } | |
37 | }); | |
38 | }; | |
39 | ||
40 | Ext.apply(me, { | |
41 | queue: function(store, cb) { | |
42 | var storeid = store.storeid; | |
43 | if (!storeid) { | |
44 | throw "unable to queue store without storeid"; | |
45 | } | |
46 | if (!queue_idx[storeid]) { | |
47 | queue_idx[storeid] = { | |
48 | store: store, | |
49 | callback: cb | |
50 | }; | |
51 | queue.push(storeid); | |
52 | } | |
53 | start_update(); | |
54 | } | |
55 | }); | |
56 | } | |
57 | }); |