Consider event time when reading FolderSummary

This commit is contained in:
Martchus 2017-08-23 23:57:26 +02:00
parent 4136e23148
commit 85ac283455
3 changed files with 12 additions and 14 deletions

View File

@ -1505,7 +1505,6 @@ void SyncthingConnection::readDirEvent(DateTime eventTime, const QString &eventT
int index;
if (SyncthingDir *dirInfo = findDirInfo(dir, index)) {
if (eventType == QLatin1String("FolderErrors")) {
// check for errors
const QJsonArray errors(eventData.value(QStringLiteral("errors")).toArray());
if (errors.isEmpty()) {
return;
@ -1532,10 +1531,8 @@ void SyncthingConnection::readDirEvent(DateTime eventTime, const QString &eventT
}
emit dirStatusChanged(*dirInfo, index);
} else if (eventType == QLatin1String("FolderSummary")) {
// check for summary
readDirSummary(eventData.value(QStringLiteral("summary")).toObject(), *dirInfo, index);
readDirSummary(eventTime, eventData.value(QStringLiteral("summary")).toObject(), *dirInfo, index);
} else if (eventType == QLatin1String("FolderCompletion")) {
// check for progress percentage
//const QString device(eventData.value(QStringLiteral("device")).toString());
int percentage = eventData.value(QStringLiteral("completion")).toInt();
if (percentage > 0 && percentage < 100 && (dirInfo->progressPercentage <= 0 || percentage < dirInfo->progressPercentage)) {
@ -1777,7 +1774,7 @@ void SyncthingConnection::readDirStatus()
return;
}
readDirSummary(replyDoc.object(), *dir, index);
readDirSummary(DateTime::gmtNow(), replyDoc.object(), *dir, index);
break;
}
default:
@ -1788,9 +1785,9 @@ void SyncthingConnection::readDirStatus()
/*!
* \brief Reads data from requestDirStatus() and FolderSummary-event and stores them to \a dir.
*/
void SyncthingConnection::readDirSummary(const QJsonObject &summary, SyncthingDir &dir, int index)
void SyncthingConnection::readDirSummary(DateTime eventTime, const QJsonObject &summary, SyncthingDir &dir, int index)
{
if (summary.isEmpty()) {
if (summary.isEmpty() || dir.lastStatisticsUpdate > eventTime) {
return;
}
@ -1798,7 +1795,7 @@ void SyncthingConnection::readDirSummary(const QJsonObject &summary, SyncthingDi
dir.globalBytes = toUInt64(summary.value(QStringLiteral("globalBytes")));
dir.globalDeleted = toUInt64(summary.value(QStringLiteral("globalDeleted")));
dir.globalFiles = toUInt64(summary.value(QStringLiteral("globalFiles")));
dir.globalFiles = toUInt64(summary.value(QStringLiteral("globalDirectories")));
dir.globalDirs = toUInt64(summary.value(QStringLiteral("globalDirectories")));
dir.localBytes = toUInt64(summary.value(QStringLiteral("localBytes")));
dir.localDeleted = toUInt64(summary.value(QStringLiteral("localDeleted")));
dir.localFiles = toUInt64(summary.value(QStringLiteral("localFiles")));
@ -1806,13 +1803,13 @@ void SyncthingConnection::readDirSummary(const QJsonObject &summary, SyncthingDi
dir.neededByted = toUInt64(summary.value(QStringLiteral("needByted")));
dir.neededFiles = toUInt64(summary.value(QStringLiteral("needFiles")));
dir.ignorePatterns = summary.value(QStringLiteral("ignorePatterns")).toBool();
dir.lastStatisticsUpdate = eventTime;
// update status
const QString state(summary.value(QStringLiteral("state")).toString());
if (!state.isEmpty()) {
try {
const auto stateChanged = DateTime::fromIsoStringLocal(summary.value(QStringLiteral("stateChanged")).toString().toUtf8().data());
dir.assignStatus(state, stateChanged);
dir.assignStatus(state, DateTime::fromIsoStringLocal(summary.value(QStringLiteral("stateChanged")).toString().toUtf8().data()));
} catch (const ConversionException &) {
// FIXME: warning about invalid stateChanged
}

View File

@ -204,7 +204,7 @@ private Q_SLOTS:
void readRestart();
void readShutdown();
void readDirStatus();
void readDirSummary(const QJsonObject &summary, SyncthingDir &dirInfo, int index);
void readDirSummary(ChronoUtilities::DateTime eventTime, const QJsonObject &summary, SyncthingDir &dirInfo, int index);
void continueConnecting();
void continueReconnecting();

View File

@ -79,7 +79,6 @@ struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDir {
int rescanInterval = 0;
int minDiskFreePercentage = 0;
SyncthingDirStatus status = SyncthingDirStatus::Idle;
bool paused = false;
ChronoUtilities::DateTime lastStatusUpdate;
int progressPercentage = 0;
int progressRate = 0;
@ -89,15 +88,17 @@ struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDir {
quint64 globalBytes = 0, globalDeleted = 0, globalFiles = 0, globalDirs = 0;
quint64 localBytes = 0, localDeleted = 0, localFiles = 0, localDirs = 0;
quint64 neededByted = 0, neededFiles = 0, neededDirs = 0;
ChronoUtilities::DateTime lastStatisticsUpdate;
ChronoUtilities::DateTime lastScanTime;
ChronoUtilities::DateTime lastFileTime;
QString lastFileName;
bool lastFileDeleted = false;
std::vector<SyncthingItemDownloadProgress> downloadingItems;
int blocksAlreadyDownloaded = 0;
int blocksToBeDownloaded = 0;
unsigned int downloadPercentage = 0;
QString downloadLabel;
unsigned int downloadPercentage = 0;
bool paused = false;
bool lastFileDeleted = false;
private:
bool checkWhetherStatusUpdateRelevant(ChronoUtilities::DateTime time);