aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Vijay A <avijayr@protonmail.com>2021-08-22 09:51:52 +0530
committerLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-08-22 16:06:30 +0530
commit5197550655c13064235bd1665233185cf8fc6d4c (patch)
tree113e73929a969ccfa82ef3d1a24556fffab527ad /src
parentfix: audio toggle is now decoupled from notification toggle (diff)
downloadferdium-app-5197550655c13064235bd1665233185cf8fc6d4c.tar.gz
ferdium-app-5197550655c13064235bd1665233185cf8fc6d4c.tar.zst
ferdium-app-5197550655c13064235bd1665233185cf8fc6d4c.zip
refactor (perf): Do not double-loop through the same list of services while marking inactive.
Diffstat (limited to 'src')
-rw-r--r--src/stores/ServicesStore.js28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index 0708aaa95..5610f7a22 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -215,12 +215,12 @@ export default class ServicesStore extends Store {
215 * Run various maintenance tasks on services 215 * Run various maintenance tasks on services
216 */ 216 */
217 _serviceMaintenance() { 217 _serviceMaintenance() {
218 this.all.forEach(service => { 218 this.enabled.forEach(service => {
219 // Defines which services should be hibernated or woken up 219 // Defines which services should be hibernated or woken up
220 if (!service.isActive) { 220 if (!service.isActive) {
221 if ( 221 if (
222 !service.lastHibernated && 222 !service.lastHibernated &&
223 Date.now() - service.lastUsed > 223 (Date.now() - service.lastUsed) >
224 ms(`${this.stores.settings.all.app.hibernationStrategy}s`) 224 ms(`${this.stores.settings.all.app.hibernationStrategy}s`)
225 ) { 225 ) {
226 // If service is stale, hibernate it. 226 // If service is stale, hibernate it.
@@ -229,21 +229,18 @@ export default class ServicesStore extends Store {
229 229
230 if ( 230 if (
231 service.lastHibernated && 231 service.lastHibernated &&
232 Number(this.stores.settings.all.app.wakeUpStrategy) > 0 232 Number(this.stores.settings.all.app.wakeUpStrategy) > 0 &&
233 (Date.now() - service.lastHibernated) >
234 ms(`${this.stores.settings.all.app.wakeUpStrategy}s`)
233 ) { 235 ) {
234 // If service is in hibernation and the wakeup time has elapsed, wake it. 236 // If service is in hibernation and the wakeup time has elapsed, wake it.
235 if ( 237 this._awake({ serviceId: service.id });
236 Date.now() - service.lastHibernated >
237 ms(`${this.stores.settings.all.app.wakeUpStrategy}s`)
238 ) {
239 this._awake({ serviceId: service.id });
240 }
241 } 238 }
242 } 239 }
243 240
244 if ( 241 if (
245 service.lastPoll && 242 service.lastPoll &&
246 service.lastPoll - service.lastPollAnswer > ms('1m') 243 (service.lastPoll - service.lastPollAnswer) > ms('1m')
247 ) { 244 ) {
248 // If service did not reply for more than 1m try to reload. 245 // If service did not reply for more than 1m try to reload.
249 if (!service.isActive) { 246 if (!service.isActive) {
@@ -621,9 +618,8 @@ export default class ServicesStore extends Store {
621 this.allDisplayed.length, 618 this.allDisplayed.length,
622 ); 619 );
623 620
624 // TODO: simplify this; 621 this.all.forEach(s => {
625 this.all.forEach((s, index) => { 622 s.isActive = false;
626 this.all[index].isActive = false;
627 }); 623 });
628 this.allDisplayed[nextIndex].isActive = true; 624 this.allDisplayed[nextIndex].isActive = true;
629 } 625 }
@@ -635,9 +631,8 @@ export default class ServicesStore extends Store {
635 this.allDisplayed.length, 631 this.allDisplayed.length,
636 ); 632 );
637 633
638 // TODO: simplify this; 634 this.all.forEach(s => {
639 this.all.forEach((s, index) => { 635 s.isActive = false;
640 this.all[index].isActive = false;
641 }); 636 });
642 this.allDisplayed[prevIndex].isActive = true; 637 this.allDisplayed[prevIndex].isActive = true;
643 } 638 }
@@ -902,6 +897,7 @@ export default class ServicesStore extends Store {
902 ); 897 );
903 898
904 const services = {}; 899 const services = {};
900 // TODO: simplify this
905 this.all.forEach((s, index) => { 901 this.all.forEach((s, index) => {
906 services[this.all[index].id] = index; 902 services[this.all[index].id] = index;
907 }); 903 });