Merge pull request #1802 from nextcloud/feature/update-segment

Updater: Add query-parameter 'updatesegment' to the update check
This commit is contained in:
Michael Schuster 2020-02-21 23:39:10 +01:00 committed by GitHub
commit 5ab20d4ab1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View 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;
}

View 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);

View 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);