From 9c8a0204e57bdc2867f02ce12e237a507d1591a5 Mon Sep 17 00:00:00 2001 From: Michael Schuster Date: Fri, 21 Feb 2020 21:28:42 +0100 Subject: [PATCH] Updater: Add query-parameter 'updatesegment' to the update check Used to throttle down desktop release rollout in order to keep the update servers alive at peak times. See: https://github.com/nextcloud/client_updater_server/pull/36 Targeted issues: #1795, #1800 Signed-off-by: Michael Schuster --- src/gui/updater/updater.cpp | 6 ++++++ src/libsync/configfile.cpp | 16 ++++++++++++++++ src/libsync/configfile.h | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/src/gui/updater/updater.cpp b/src/gui/updater/updater.cpp index 3a247d6b2..227d67afd 100644 --- a/src/gui/updater/updater.cpp +++ b/src/gui/updater/updater.cpp @@ -25,6 +25,7 @@ #include "version.h" #include "config.h" +#include "configfile.h" namespace OCC { @@ -75,6 +76,11 @@ QUrlQuery Updater::getQueryParams() // to beta channel } + // updateSegment (see configfile.h) + ConfigFile cfg; + auto updateSegment = cfg.updateSegment(); + query.addQueryItem(QLatin1String("updatesegment"), QString::number(updateSegment)); + return query; } diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index bfed34844..69de66cf4 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -64,6 +64,7 @@ static const char optionalServerNotificationsC[] = "optionalServerNotifications" static const char showInExplorerNavigationPaneC[] = "showInExplorerNavigationPane"; static const char skipUpdateCheckC[] = "skipUpdateCheck"; static const char updateCheckIntervalC[] = "updateCheckInterval"; +static const char updateSegmentC[] = "updateSegment"; static const char geometryC[] = "geometry"; static const char timeoutC[] = "timeout"; static const char chunkSizeC[] = "chunkSize"; @@ -576,6 +577,21 @@ void ConfigFile::setSkipUpdateCheck(bool skip, const QString &connection) settings.sync(); } +int ConfigFile::updateSegment() const +{ + QSettings settings(configFile(), QSettings::IniFormat); + int segment = settings.value(QLatin1String(updateSegmentC), -1).toInt(); + + // Invalid? (Unset at the very first launch) + if(segment < 0 || segment > 99) { + // Save valid segment value, normally has to be done only once. + segment = qrand() % 99; + settings.setValue(QLatin1String(updateSegmentC), segment); + } + + return segment; +} + int ConfigFile::maxLogLines() const { QSettings settings(configFile(), QSettings::IniFormat); diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index e84e8b2f3..2fb911c9b 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -149,6 +149,11 @@ public: bool skipUpdateCheck(const QString &connection = QString()) const; void setSkipUpdateCheck(bool, const QString &); + /** Query-parameter 'updatesegment' for the update check, value between 0 and 99. + Used to throttle down desktop release rollout in order to keep the update servers alive at peak times. + See: https://github.com/nextcloud/client_updater_server/pull/36 */ + int updateSegment() const; + void saveGeometryHeader(QHeaderView *header); void restoreGeometryHeader(QHeaderView *header);