diff options
author | 2022-03-01 15:25:55 +0100 | |
---|---|---|
committer | 2022-03-01 15:25:55 +0100 | |
commit | 3dcc5a9ee745759cd3a289c26dacc08213feccbd (patch) | |
tree | d5cf439acece73d02b1ac624fb4f74e5fd03126f /src/stores | |
parent | 5.7.0 (diff) | |
parent | New Crowdin updates (#2429) (diff) | |
download | ferdium-app-3dcc5a9ee745759cd3a289c26dacc08213feccbd.tar.gz ferdium-app-3dcc5a9ee745759cd3a289c26dacc08213feccbd.tar.zst ferdium-app-3dcc5a9ee745759cd3a289c26dacc08213feccbd.zip |
Merge branch 'develop' into release
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/ServicesStore.js | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index e546850f9..e2bfd22f3 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -239,7 +239,7 @@ export default class ServicesStore extends Store { | |||
239 | ms(`${this.stores.settings.all.app.wakeUpStrategy}s`) | 239 | ms(`${this.stores.settings.all.app.wakeUpStrategy}s`) |
240 | ) { | 240 | ) { |
241 | // If service is in hibernation and the wakeup time has elapsed, wake it. | 241 | // If service is in hibernation and the wakeup time has elapsed, wake it. |
242 | this._awake({ serviceId: service.id }); | 242 | this._awake({ serviceId: service.id, automatic: true }); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
@@ -1043,11 +1043,59 @@ export default class ServicesStore extends Store { | |||
1043 | service.lastHibernated = Date.now(); | 1043 | service.lastHibernated = Date.now(); |
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | @action _awake({ serviceId }) { | 1046 | @action _awake({ serviceId, automatic }) { |
1047 | const now = Date.now(); | ||
1047 | const service = this.one(serviceId); | 1048 | const service = this.one(serviceId); |
1048 | debug(`Waking up from service hibernation for ${service.name}`); | 1049 | const automaticTag = automatic ? ' automatically ' : ' '; |
1050 | debug( | ||
1051 | `Waking up${automaticTag}from service hibernation for ${service.name}`, | ||
1052 | ); | ||
1053 | |||
1054 | if (automatic) { | ||
1055 | // if this is an automatic wake up, use the wakeUpHibernationStrategy | ||
1056 | // which sets the lastUsed time to an offset from now rather than to now. | ||
1057 | // Also add an optional random splay to desync the wakeups and | ||
1058 | // potentially reduce load. | ||
1059 | // | ||
1060 | // offsetNow = now - (hibernationStrategy - wakeUpHibernationStrategy) | ||
1061 | // | ||
1062 | // if wUHS = hS = 60, offsetNow = now. hibernation again in 60 seconds. | ||
1063 | // | ||
1064 | // if wUHS = 20 and hS = 60, offsetNow = now - 40. hibernation again in | ||
1065 | // 20 seconds. | ||
1066 | // | ||
1067 | // possibly also include splay in wUHS before subtracting from hS. | ||
1068 | // | ||
1069 | const mainStrategy = this.stores.settings.all.app.hibernationStrategy; | ||
1070 | let strategy = this.stores.settings.all.app.wakeUpHibernationStrategy; | ||
1071 | debug(`wakeUpHibernationStrategy = ${strategy}`); | ||
1072 | debug(`hibernationStrategy = ${mainStrategy}`); | ||
1073 | if (!strategy || strategy < 1) { | ||
1074 | strategy = this.stores.settings.all.app.hibernationStrategy; | ||
1075 | } | ||
1076 | let splay = 0; | ||
1077 | // Add splay. This will keep the service awake a little longer. | ||
1078 | if ( | ||
1079 | this.stores.settings.all.app.wakeUpHibernationSplay && | ||
1080 | Math.random() >= 0.5 | ||
1081 | ) { | ||
1082 | // Add 10 additional seconds 50% of the time. | ||
1083 | splay = 10; | ||
1084 | debug('Added splay'); | ||
1085 | } else { | ||
1086 | debug('skipping splay'); | ||
1087 | } | ||
1088 | // wake up again in strategy + splay seconds instead of mainStrategy seconds. | ||
1089 | service.lastUsed = now - ms(`${mainStrategy - (strategy + splay)}s`); | ||
1090 | } else { | ||
1091 | service.lastUsed = now; | ||
1092 | } | ||
1093 | debug( | ||
1094 | `Setting service.lastUsed to ${service.lastUsed} (${ | ||
1095 | (now - service.lastUsed) / 1000 | ||
1096 | }s ago)`, | ||
1097 | ); | ||
1049 | service.isHibernationRequested = false; | 1098 | service.isHibernationRequested = false; |
1050 | service.lastUsed = Date.now(); | ||
1051 | service.lastHibernated = null; | 1099 | service.lastHibernated = null; |
1052 | } | 1100 | } |
1053 | 1101 | ||