Updater: Add query-parameter 'updatesegment' to the update check
authorMichael Schuster <michael@schuster.ms>
Fri, 21 Feb 2020 20:28:42 +0000 (21:28 +0100)
committerMichael Schuster <michael@schuster.ms>
Fri, 21 Feb 2020 20:28:42 +0000 (21:28 +0100)
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 <michael@schuster.ms>
src/gui/updater/updater.cpp
src/libsync/configfile.cpp
src/libsync/configfile.h

index 3a247d6b28d46bf2847b81177b52fb30a398b0f0..227d67afdcf6a698a14f14475ce4b5136613ff5e 100644 (file)
@@ -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;
 }
 
index bfed34844e63389257219d4ac3fa81ad868820d0..69de66cf4a16be85eddba329bbcc8a5fc17fcfe0 100644 (file)
@@ -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);
index e84e8b2f3bd3e1f4e61ced0b090e73950905180e..2fb911c9b14df650dc9009ff4f877b00ef6f8397 100644 (file)
@@ -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);