1
0
mirror of https://github.com/chylex/Nextcloud-Desktop.git synced 2025-05-12 05:34:09 +02:00

Use std::chrono::milliseconds to represent milliseconds

This commit is contained in:
Olivier Goffart 2018-01-23 22:51:25 +01:00 committed by Camila San
parent ea58a1038b
commit 073a5184cb
No known key found for this signature in database
GPG Key ID: 7A4A6121E88E2AD4
12 changed files with 89 additions and 82 deletions

View File

@ -214,11 +214,11 @@ void AccountState::checkConnectivity()
// IF the account is connected the connection check can be skipped
// if the last successful etag check job is not so long ago.
ConfigFile cfg;
int polltime = cfg.remotePollInterval();
std::chrono::milliseconds polltime = cfg.remotePollInterval();
if (isConnected() && _timeSinceLastETagCheck.isValid()
&& _timeSinceLastETagCheck.elapsed() < polltime) {
qCDebug(lcAccountState) << account()->displayName() << "The last ETag check succeeded within the last " << polltime / 1000 << " secs. No connection check needed!";
&& _timeSinceLastETagCheck.hasExpired(polltime.count())) {
qCDebug(lcAccountState) << account()->displayName() << "The last ETag check succeeded within the last " << polltime.count() / 1000 << " secs. No connection check needed!";
return;
}

View File

@ -533,10 +533,10 @@ ActivitySettings::ActivitySettings(QWidget *parent)
_tab->setCurrentIndex(1);
}
void ActivitySettings::setNotificationRefreshInterval(quint64 interval)
void ActivitySettings::setNotificationRefreshInterval(std::chrono::milliseconds interval)
{
qCDebug(lcActivity) << "Starting Notification refresh timer with " << interval / 1000 << " sec interval";
_notificationCheckTimer.start(interval);
qCDebug(lcActivity) << "Starting Notification refresh timer with " << interval.count() / 1000 << " sec interval";
_notificationCheckTimer.start(interval.count());
}
void ActivitySettings::setActivityTabHidden(bool hidden)

View File

@ -19,6 +19,7 @@
#include <QDateTime>
#include <QLocale>
#include <QAbstractListModel>
#include <chrono>
#include "progressdispatcher.h"
#include "owncloudgui.h"
@ -137,7 +138,7 @@ public slots:
void slotRefresh(AccountState *ptr);
void slotRemoveAccount(AccountState *ptr);
void setNotificationRefreshInterval(quint64 interval);
void setNotificationRefreshInterval(std::chrono::milliseconds interval);
void slotShowIssuesTab(const QString &folderAlias);

View File

@ -635,18 +635,17 @@ void Folder::startSync(const QStringList &pathList)
setDirtyNetworkLimits();
setSyncOptions();
static qint64 fullLocalDiscoveryInterval = []() {
static std::chrono::milliseconds fullLocalDiscoveryInterval = []() {
auto interval = ConfigFile().fullLocalDiscoveryInterval();
QByteArray env = qgetenv("OWNCLOUD_FULL_LOCAL_DISCOVERY_INTERVAL");
if (!env.isEmpty()) {
interval = env.toLongLong();
interval = std::chrono::milliseconds(env.toLongLong());
}
return interval;
}();
if (_folderWatcher && _folderWatcher->isReliable()
&& _timeSinceLastFullLocalDiscovery.isValid()
&& (fullLocalDiscoveryInterval < 0
|| _timeSinceLastFullLocalDiscovery.elapsed() < fullLocalDiscoveryInterval)) {
if (_folderWatcher && _folderWatcher->isReliable() && _timeSinceLastFullLocalDiscovery.isValid()
&& (fullLocalDiscoveryInterval.count() < 0
|| _timeSinceLastFullLocalDiscovery.hasExpired(fullLocalDiscoveryInterval.count()))) {
qCInfo(lcFolder) << "Allowing local discovery to read from the database";
_engine->setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, _localDiscoveryPaths);
@ -710,7 +709,7 @@ void Folder::setSyncOptions()
QByteArray targetChunkUploadDurationEnv = qgetenv("OWNCLOUD_TARGET_CHUNK_UPLOAD_DURATION");
if (!targetChunkUploadDurationEnv.isEmpty()) {
opt._targetChunkUploadDuration = targetChunkUploadDurationEnv.toUInt();
opt._targetChunkUploadDuration = std::chrono::milliseconds(targetChunkUploadDurationEnv.toUInt());
} else {
opt._targetChunkUploadDuration = cfgFile.targetChunkUploadDuration();
}
@ -832,7 +831,7 @@ void Folder::slotSyncFinished(bool success)
// all come in.
QTimer::singleShot(200, this, &Folder::slotEmitFinishedDelayed);
_lastSyncDuration = _timeSinceLastSyncStart.elapsed();
_lastSyncDuration = std::chrono::milliseconds(_timeSinceLastSyncStart.elapsed());
_timeSinceLastSyncDone.start();
// Increment the follow-up sync counter if necessary.

View File

@ -28,6 +28,7 @@
#include <QStringList>
#include <QUuid>
#include <set>
#include <chrono>
class QThread;
class QSettings;
@ -193,8 +194,8 @@ public:
SyncEngine &syncEngine() { return *_engine; }
RequestEtagJob *etagJob() { return _requestEtagJob; }
qint64 msecSinceLastSync() const { return _timeSinceLastSyncDone.elapsed(); }
qint64 msecLastSyncDuration() const { return _lastSyncDuration; }
std::chrono::milliseconds msecSinceLastSync() const { return std::chrono::milliseconds(_timeSinceLastSyncDone.elapsed()); }
std::chrono::milliseconds msecLastSyncDuration() const { return _lastSyncDuration; }
int consecutiveFollowUpSyncs() const { return _consecutiveFollowUpSyncs; }
int consecutiveFailingSyncs() const { return _consecutiveFailingSyncs; }
@ -355,7 +356,7 @@ private:
QElapsedTimer _timeSinceLastSyncDone;
QElapsedTimer _timeSinceLastSyncStart;
QElapsedTimer _timeSinceLastFullLocalDiscovery;
qint64 _lastSyncDuration;
std::chrono::milliseconds _lastSyncDuration;
/// The number of syncs that failed in a row.
/// Reset when a sync is successful.

View File

@ -59,9 +59,9 @@ FolderMan::FolderMan(QObject *parent)
_socketApi.reset(new SocketApi);
ConfigFile cfg;
int polltime = cfg.remotePollInterval();
qCInfo(lcFolderMan) << "setting remote poll timer interval to" << polltime << "msec";
_etagPollTimer.setInterval(polltime);
std::chrono::milliseconds polltime = cfg.remotePollInterval();
qCInfo(lcFolderMan) << "setting remote poll timer interval to" << polltime.count() << "msec";
_etagPollTimer.setInterval(polltime.count());
QObject::connect(&_etagPollTimer, &QTimer::timeout, this, &FolderMan::slotEtagPollTimerTimeout);
_etagPollTimer.start();
@ -653,13 +653,13 @@ void FolderMan::startScheduledSyncSoon()
// Require a pause based on the duration of the last sync run.
if (Folder *lastFolder = _lastSyncFolder) {
msSinceLastSync = lastFolder->msecSinceLastSync();
msSinceLastSync = lastFolder->msecSinceLastSync().count();
// 1s -> 1.5s pause
// 10s -> 5s pause
// 1min -> 12s pause
// 1h -> 90s pause
qint64 pause = qSqrt(lastFolder->msecLastSyncDuration()) / 20.0 * 1000.0;
qint64 pause = qSqrt(lastFolder->msecLastSyncDuration().count()) / 20.0 * 1000.0;
msDelay = qMax(msDelay, pause);
}
@ -724,7 +724,7 @@ void FolderMan::slotStartScheduledFolderSync()
void FolderMan::slotEtagPollTimerTimeout()
{
ConfigFile cfg;
int polltime = cfg.remotePollInterval();
auto polltime = cfg.remotePollInterval();
foreach (Folder *f, _folderMap) {
if (!f) {
@ -808,11 +808,10 @@ void FolderMan::slotScheduleFolderByTime()
auto msecsSinceSync = f->msecSinceLastSync();
// Possibly it's just time for a new sync run
bool forceSyncIntervalExpired =
quint64(msecsSinceSync) > ConfigFile().forceSyncInterval();
bool forceSyncIntervalExpired = msecsSinceSync > ConfigFile().forceSyncInterval();
if (forceSyncIntervalExpired) {
qCInfo(lcFolderMan) << "Scheduling folder" << f->alias()
<< "because it has been" << msecsSinceSync << "ms "
<< "because it has been" << msecsSinceSync.count() << "ms "
<< "since the last sync";
scheduleFolder(f);
@ -823,16 +822,15 @@ void FolderMan::slotScheduleFolderByTime()
bool syncAgain =
(f->consecutiveFailingSyncs() > 0 && f->consecutiveFailingSyncs() < 3)
|| f->syncEngine().isAnotherSyncNeeded() == DelayedFollowUp;
qint64 syncAgainDelay = 10 * 1000; // 10s for the first retry-after-fail
auto syncAgainDelay = std::chrono::seconds(10); // 10s for the first retry-after-fail
if (f->consecutiveFailingSyncs() > 1)
syncAgainDelay = 60 * 1000; // 60s for each further attempt
if (syncAgain
&& msecsSinceSync > syncAgainDelay) {
syncAgainDelay = std::chrono::seconds(60); // 60s for each further attempt
if (syncAgain && msecsSinceSync > syncAgainDelay) {
qCInfo(lcFolderMan) << "Scheduling folder" << f->alias()
<< ", the last" << f->consecutiveFailingSyncs() << "syncs failed"
<< ", anotherSyncNeeded" << f->syncEngine().isAnotherSyncNeeded()
<< ", last status:" << f->syncResult().statusString()
<< ", time since last sync:" << msecsSinceSync;
<< ", time since last sync:" << msecsSinceSync.count();
scheduleFolder(f);
continue;

View File

@ -54,7 +54,7 @@ UpdaterScheduler::UpdaterScheduler(QObject *parent)
ConfigFile cfg;
auto checkInterval = cfg.updateCheckInterval();
_updateCheckTimer.start(checkInterval);
_updateCheckTimer.start(std::chrono::milliseconds(checkInterval).count());
}
void UpdaterScheduler::slotTimerFired()
@ -62,7 +62,7 @@ void UpdaterScheduler::slotTimerFired()
ConfigFile cfg;
// re-set the check interval if it changed in the config file meanwhile
auto checkInterval = cfg.updateCheckInterval();
auto checkInterval = std::chrono::milliseconds(cfg.updateCheckInterval()).count();
if (checkInterval != _updateCheckTimer.interval()) {
_updateCheckTimer.setInterval(checkInterval);
qCInfo(lcUpdater) << "Setting new update check interval " << checkInterval;

View File

@ -38,12 +38,13 @@
#include <QStandardPaths>
#define DEFAULT_REMOTE_POLL_INTERVAL 30000 // default remote poll time in milliseconds
#define DEFAULT_FULL_LOCAL_DISCOVERY_INTERVAL (60 * 60 * 1000) // 1 hour
#define DEFAULT_MAX_LOG_LINES 20000
namespace OCC {
Q_LOGGING_CATEGORY(lcConfigFile, "nextcloud.sync.configfile", QtInfoMsg)
namespace chrono = std::chrono;
Q_LOGGING_CATEGORY(lcConfigFile, "sync.configfile", QtInfoMsg)
//static const char caCertsKeyC[] = "CaCertificates"; only used from account.cpp
static const char remotePollIntervalC[] = "remotePollInterval";
@ -89,6 +90,12 @@ const char certPasswd[] = "http_certificatePasswd";
QString ConfigFile::_confDir = QString();
bool ConfigFile::_askedUser = false;
static chrono::milliseconds millisecondsValue(const QSettings &setting, const char *key,
chrono::milliseconds defaultValue)
{
return chrono::milliseconds(setting.value(QLatin1String(key), qlonglong(defaultValue.count())).toLongLong());
};
ConfigFile::ConfigFile()
{
// QDesktopServices uses the application name to create a config path
@ -173,10 +180,10 @@ quint64 ConfigFile::minChunkSize() const
return settings.value(QLatin1String(minChunkSizeC), 1000 * 1000).toLongLong(); // default to 1 MB
}
quint64 ConfigFile::targetChunkUploadDuration() const
chrono::milliseconds ConfigFile::targetChunkUploadDuration() const
{
QSettings settings(configFile(), QSettings::IniFormat);
return settings.value(QLatin1String(targetChunkUploadDurationC), 60 * 1000).toLongLong(); // default to 1 minute
return millisecondsValue(settings, targetChunkUploadDurationC, chrono::minutes(1));
}
void ConfigFile::setOptionalServerNotifications(bool show)
@ -386,7 +393,7 @@ bool ConfigFile::dataExists(const QString &group, const QString &key) const
return settings.contains(key);
}
int ConfigFile::remotePollInterval(const QString &connection) const
chrono::milliseconds ConfigFile::remotePollInterval(const QString &connection) const
{
QString con(connection);
if (connection.isEmpty())
@ -395,33 +402,34 @@ int ConfigFile::remotePollInterval(const QString &connection) const
QSettings settings(configFile(), QSettings::IniFormat);
settings.beginGroup(con);
int remoteInterval = settings.value(QLatin1String(remotePollIntervalC), DEFAULT_REMOTE_POLL_INTERVAL).toInt();
if (remoteInterval < 5000) {
auto defaultPollInterval = chrono::milliseconds(DEFAULT_REMOTE_POLL_INTERVAL);
auto remoteInterval = millisecondsValue(settings, remotePollIntervalC, defaultPollInterval);
if (remoteInterval < chrono::seconds(5)) {
qCWarning(lcConfigFile) << "Remote Interval is less than 5 seconds, reverting to" << DEFAULT_REMOTE_POLL_INTERVAL;
remoteInterval = DEFAULT_REMOTE_POLL_INTERVAL;
remoteInterval = defaultPollInterval;
}
return remoteInterval;
}
void ConfigFile::setRemotePollInterval(int interval, const QString &connection)
void ConfigFile::setRemotePollInterval(chrono::milliseconds interval, const QString &connection)
{
QString con(connection);
if (connection.isEmpty())
con = defaultConnection();
if (interval < 5000) {
qCWarning(lcConfigFile) << "Remote Poll interval of " << interval << " is below five seconds.";
if (interval < chrono::seconds(5)) {
qCWarning(lcConfigFile) << "Remote Poll interval of " << interval.count() << " is below five seconds.";
return;
}
QSettings settings(configFile(), QSettings::IniFormat);
settings.beginGroup(con);
settings.setValue(QLatin1String(remotePollIntervalC), interval);
settings.setValue(QLatin1String(remotePollIntervalC), qlonglong(interval.count()));
settings.sync();
}
quint64 ConfigFile::forceSyncInterval(const QString &connection) const
chrono::milliseconds ConfigFile::forceSyncInterval(const QString &connection) const
{
uint pollInterval = remotePollInterval(connection);
auto pollInterval = remotePollInterval(connection);
QString con(connection);
if (connection.isEmpty())
@ -429,23 +437,23 @@ quint64 ConfigFile::forceSyncInterval(const QString &connection) const
QSettings settings(configFile(), QSettings::IniFormat);
settings.beginGroup(con);
quint64 defaultInterval = 2 * 60 * 60 * 1000ull; // 2h
quint64 interval = settings.value(QLatin1String(forceSyncIntervalC), defaultInterval).toULongLong();
auto defaultInterval = chrono::hours(2);
auto interval = millisecondsValue(settings, forceSyncIntervalC, defaultInterval);
if (interval < pollInterval) {
qCWarning(lcConfigFile) << "Force sync interval is less than the remote poll inteval, reverting to" << pollInterval;
qCWarning(lcConfigFile) << "Force sync interval is less than the remote poll inteval, reverting to" << pollInterval.count();
interval = pollInterval;
}
return interval;
}
qint64 ConfigFile::fullLocalDiscoveryInterval() const
chrono::milliseconds OCC::ConfigFile::fullLocalDiscoveryInterval() const
{
QSettings settings(configFile(), QSettings::IniFormat);
settings.beginGroup(defaultConnection());
return settings.value(QLatin1String(fullLocalDiscoveryIntervalC), DEFAULT_FULL_LOCAL_DISCOVERY_INTERVAL).toLongLong();
return millisecondsValue(settings, fullLocalDiscoveryIntervalC, chrono::hours(1));
}
quint64 ConfigFile::notificationRefreshInterval(const QString &connection) const
chrono::milliseconds ConfigFile::notificationRefreshInterval(const QString &connection) const
{
QString con(connection);
if (connection.isEmpty())
@ -453,16 +461,16 @@ quint64 ConfigFile::notificationRefreshInterval(const QString &connection) const
QSettings settings(configFile(), QSettings::IniFormat);
settings.beginGroup(con);
quint64 defaultInterval = 5 * 60 * 1000ull; // 5 minutes
quint64 interval = settings.value(QLatin1String(notificationRefreshIntervalC), defaultInterval).toULongLong();
if (interval < 60 * 1000ull) {
auto defaultInterval = chrono::minutes(5);
auto interval = millisecondsValue(settings, notificationRefreshIntervalC, defaultInterval);
if (interval < chrono::minutes(1)) {
qCWarning(lcConfigFile) << "Notification refresh interval smaller than one minute, setting to one minute";
interval = 60 * 1000ull;
interval = chrono::minutes(1);
}
return interval;
}
int ConfigFile::updateCheckInterval(const QString &connection) const
chrono::milliseconds ConfigFile::updateCheckInterval(const QString &connection) const
{
QString con(connection);
if (connection.isEmpty())
@ -470,12 +478,12 @@ int ConfigFile::updateCheckInterval(const QString &connection) const
QSettings settings(configFile(), QSettings::IniFormat);
settings.beginGroup(con);
int defaultInterval = 1000 * 60 * 60 * 10; // ten hours
int interval = settings.value(QLatin1String(updateCheckIntervalC), defaultInterval).toInt();
auto defaultInterval = chrono::hours(10);
auto interval = millisecondsValue(settings, updateCheckIntervalC, defaultInterval);
int minInterval = 1000 * 60 * 5;
auto minInterval = chrono::minutes(5);
if (interval < minInterval) {
qCWarning(lcConfigFile) << "Update check interval less than five minutes, setting " << minInterval;
qCWarning(lcConfigFile) << "Update check interval less than five minutes, resetting to 5 minutes";
interval = minInterval;
}
return interval;

View File

@ -21,6 +21,7 @@
#include <QSettings>
#include <QString>
#include <QVariant>
#include <chrono>
class QWidget;
class QHeaderView;
@ -62,22 +63,22 @@ public:
void setMaxLogLines(int);
/* Server poll interval in milliseconds */
int remotePollInterval(const QString &connection = QString()) const;
std::chrono::milliseconds remotePollInterval(const QString &connection = QString()) const;
/* Set poll interval. Value in milliseconds has to be larger than 5000 */
void setRemotePollInterval(int interval, const QString &connection = QString());
void setRemotePollInterval(std::chrono::milliseconds interval, const QString &connection = QString());
/* Interval to check for new notifications */
quint64 notificationRefreshInterval(const QString &connection = QString()) const;
std::chrono::milliseconds notificationRefreshInterval(const QString &connection = QString()) const;
/* Force sync interval, in milliseconds */
quint64 forceSyncInterval(const QString &connection = QString()) const;
std::chrono::milliseconds forceSyncInterval(const QString &connection = QString()) const;
/**
* Interval in milliseconds within which full local discovery is required
*
* Use -1 to disable regular full local discoveries.
*/
qint64 fullLocalDiscoveryInterval() const;
std::chrono::milliseconds fullLocalDiscoveryInterval() const;
bool monoIcons() const;
void setMonoIcons(bool);
@ -137,13 +138,13 @@ public:
quint64 chunkSize() const;
quint64 maxChunkSize() const;
quint64 minChunkSize() const;
quint64 targetChunkUploadDuration() const;
std::chrono::milliseconds targetChunkUploadDuration() const;
void saveGeometry(QWidget *w);
void restoreGeometry(QWidget *w);
// how often the check about new versions runs, default two hours
int updateCheckInterval(const QString &connection = QString()) const;
// how often the check about new versions runs
std::chrono::milliseconds updateCheckInterval(const QString &connection = QString()) const;
bool skipUpdateCheck(const QString &connection = QString()) const;
void setSkipUpdateCheck(bool, const QString &);

View File

@ -139,9 +139,9 @@ public:
return _errorString.isEmpty() ? AbstractNetworkJob::errorString() : _errorString;
}
quint64 msSinceStart() const
std::chrono::milliseconds msSinceStart() const
{
return _requestTimer.elapsed();
return std::chrono::milliseconds(_requestTimer.elapsed());
}
signals:

View File

@ -368,12 +368,10 @@ void PropagateUploadFileNG::slotPutFinished()
//
// Dynamic chunk sizing is enabled if the server configured a
// target duration for each chunk upload.
double targetDuration = propagator()->syncOptions()._targetChunkUploadDuration;
if (targetDuration > 0) {
double uploadTime = job->msSinceStart() + 1; // add one to avoid div-by-zero
auto predictedGoodSize = static_cast<quint64>(
_currentChunkSize / uploadTime * targetDuration);
auto targetDuration = propagator()->syncOptions()._targetChunkUploadDuration;
if (targetDuration.count() > 0) {
auto uploadTime = ++job->msSinceStart(); // add one to avoid div-by-zero
qint64 predictedGoodSize = (_currentChunkSize * targetDuration) / uploadTime;
// The whole targeting is heuristic. The predictedGoodSize will fluctuate
// quite a bit because of external factors (like available bandwidth)
@ -389,8 +387,8 @@ void PropagateUploadFileNG::slotPutFinished()
targetSize,
propagator()->syncOptions()._maxChunkSize);
qCInfo(lcPropagateUpload) << "Chunked upload of" << _currentChunkSize << "bytes took" << uploadTime
<< "ms, desired is" << targetDuration << "ms, expected good chunk size is"
qCInfo(lcPropagateUpload) << "Chunked upload of" << _currentChunkSize << "bytes took" << uploadTime.count()
<< "ms, desired is" << targetDuration.count() << "ms, expected good chunk size is"
<< predictedGoodSize << "bytes and nudged next chunk size to "
<< propagator()->_chunkSize << "bytes";
}

View File

@ -16,6 +16,7 @@
#include "owncloudlib.h"
#include <QString>
#include <chrono>
namespace OCC {
@ -54,7 +55,7 @@ struct SyncOptions
*
* Set to 0 it will disable dynamic chunk sizing.
*/
quint64 _targetChunkUploadDuration = 60 * 1000; // 1 minute
std::chrono::milliseconds _targetChunkUploadDuration = std::chrono::minutes(1);
/** Whether parallel network jobs are allowed. */
bool _parallelNetworkJobs = true;