|
103 | 103 |
|
104 | 104 | this.initElements(); |
105 | 105 |
|
| 106 | + this.initProgressBatch(); |
| 107 | + |
106 | 108 | if (this.title) { |
107 | 109 | this.$header.html(this.title); |
108 | 110 | } |
109 | 111 |
|
110 | | - this.$progress.toggle(!!this.progressMax); |
| 112 | + this.$progress.show(); |
111 | 113 |
|
112 | 114 | this.$overlayElementId |
113 | 115 | .modal({ |
|
148 | 150 | typeof this.actionsCloseCallback === 'function' && this.actionsCloseCallback(); |
149 | 151 | } |
150 | 152 | }, |
| 153 | + initProgressBatch: function () { |
| 154 | + this._pendingCount = 0; |
| 155 | + this._lastValue = 0; |
| 156 | + this._flushTimer = null; |
| 157 | + }, |
151 | 158 | setProgressSite: function (value) { |
152 | 159 | if (!this.$progress) return; |
153 | 160 |
|
154 | | - // update label |
155 | | - this.setStatusText(`${value} / ${this.totalSites} ${this.statusText}`); |
| 161 | + this._pendingCount = (this._pendingCount || 0) + 1; |
| 162 | + this._lastValue = value; |
| 163 | + |
| 164 | + if (this._rafScheduled) return; |
| 165 | + |
| 166 | + this._rafScheduled = true; |
| 167 | + |
| 168 | + requestAnimationFrame(() => { |
| 169 | + this.flushProgress(); |
| 170 | + this._rafScheduled = false; |
| 171 | + }); |
| 172 | + }, |
| 173 | + flushProgress: function () { |
| 174 | + if (!this.$progress) return; |
| 175 | + |
| 176 | + // update label once |
| 177 | + this.setStatusText( |
| 178 | + `${this._lastValue} / ${this.totalSites} ${this.statusText}` |
| 179 | + ); |
156 | 180 |
|
157 | | - // increment progress safely |
| 181 | + // batch increment |
158 | 182 | const current = this.$progress.progress('get value') || 0; |
159 | | - this.$progress.progress('set progress', current + 1); |
| 183 | + this.$progress.progress('set progress', current + this._pendingCount); |
| 184 | + |
| 185 | + // reset |
| 186 | + this._pendingCount = 0; |
| 187 | + this._flushTimer = null; |
160 | 188 | }, |
161 | 189 | getProgressValue: function () { |
162 | 190 | return this.$progress |
|
0 commit comments