From 63c54b5611f575f89cb682373241184a7d88ad5d Mon Sep 17 00:00:00 2001 From: bbedward Date: Thu, 11 Sep 2025 22:52:01 -0400 Subject: [PATCH] re-nice weather curl commands --- Services/WeatherService.qml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Services/WeatherService.qml b/Services/WeatherService.qml index 0d3d7e64..b78d8523 100644 --- a/Services/WeatherService.qml +++ b/Services/WeatherService.qml @@ -42,6 +42,9 @@ Singleton { property int minFetchInterval: 30000 property int persistentRetryCount: 0 + readonly property var lowPriorityCmd: ["nice", "-n", "19", "ionice", "-c3"] + readonly property var curlBaseCmd: ["curl", "-sS", "--fail", "--connect-timeout", "3", "--max-time", "6", "--limit-rate", "100k", "--compressed"] + property var weatherIcons: ({ "0": "clear_day", "1": "clear_day", @@ -235,12 +238,13 @@ Singleton { } function getLocationFromCoords(lat, lon) { - reverseGeocodeFetcher.command = ["bash", "-c", "curl -s --connect-timeout 10 --max-time 30 'https://nominatim.openstreetmap.org/reverse?lat=" + lat + "&lon=" + lon + "&format=json&addressdetails=1&accept-language=en' -H 'User-Agent: DankMaterialShell Weather Widget'"] + const url = "https://nominatim.openstreetmap.org/reverse?lat=" + lat + "&lon=" + lon + "&format=json&addressdetails=1&accept-language=en" + reverseGeocodeFetcher.command = lowPriorityCmd.concat(curlBaseCmd).concat(["-H", "User-Agent: DankMaterialShell Weather Widget", url]) reverseGeocodeFetcher.running = true } function getLocationFromCity(city) { - cityGeocodeFetcher.command = ["bash", "-c", "curl -s --connect-timeout 10 --max-time 30 '" + getGeocodingUrl(city) + "'"] + cityGeocodeFetcher.command = lowPriorityCmd.concat(curlBaseCmd).concat([getGeocodingUrl(city)]) cityGeocodeFetcher.running = true } @@ -274,7 +278,8 @@ Singleton { root.lastFetchTime = now root.weather.loading = true - weatherFetcher.command = ["bash", "-c", "curl -s --connect-timeout 10 --max-time 30 '" + apiUrl + "'"] + const weatherCmd = lowPriorityCmd.concat(["curl", "-sS", "--fail", "--connect-timeout", "3", "--max-time", "6", "--limit-rate", "150k", "--compressed"]) + weatherFetcher.command = weatherCmd.concat([apiUrl]) weatherFetcher.running = true } @@ -282,6 +287,11 @@ Singleton { root.lastFetchTime = 0 // Reset throttle fetchWeather() } + + function nextInterval() { + const jitter = Math.floor(Math.random() * 15000) - 7500 + return Math.max(60000, root.updateInterval + jitter) + } function handleWeatherSuccess() { root.retryAttempts = 0 @@ -312,7 +322,7 @@ Singleton { Process { id: ipLocationFetcher - command: ["curl", "-s", "--connect-timeout", "5", "--max-time", "10", "http://ipinfo.io/json"] + command: lowPriorityCmd.concat(curlBaseCmd).concat(["http://ipinfo.io/json"]) running: false stdout: StdioCollector { @@ -533,12 +543,13 @@ Singleton { Timer { id: updateTimer - interval: root.updateInterval + interval: nextInterval() running: root.refCount > 0 && SettingsData.weatherEnabled repeat: true triggeredOnStart: true onTriggered: { root.fetchWeather() + interval = nextInterval() } }