[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Jan 2 06:16:45 UTC 2017
wsd/DocumentBroker.cpp | 17 +++++++----------
wsd/DocumentBroker.hpp | 18 +++++++++---------
2 files changed, 16 insertions(+), 19 deletions(-)
New commits:
commit 28db46a59c1dd07ef1cbcc928f4de408e15bf0f3
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Jan 1 19:42:19 2017 -0500
wsd: always update the last save time to detect failures
When saving we need to differentiate between no-op
and failure. The lastSaveTime must always be updated
when saving didn't fail (i.e. no modification or saved).
Change-Id: I0e2455afac22c82f0b623f9441fbc0bca8a7cb83
Reviewed-on: https://gerrit.libreoffice.org/32629
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index dd15f06..a9a2dac 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -372,6 +372,7 @@ bool DocumentBroker::save(const std::string& sessionId, bool success, const std:
if (!success && result == "unmodified")
{
LOG_DBG("Save skipped as document [" << _docKey << "] was not modified.");
+ _lastSaveTime = std::chrono::steady_clock::now();
_saveCV.notify_all();
return true;
}
@@ -395,6 +396,7 @@ bool DocumentBroker::save(const std::string& sessionId, bool success, const std:
// Nothing to do.
LOG_DBG("Skipping unnecessary saving to URI [" << uri << "] with docKey [" << _docKey <<
"]. File last modified " << _lastFileModifiedTime.elapsed() / 1000000 << " seconds ago.");
+ _lastSaveTime = std::chrono::steady_clock::now();
_saveCV.notify_all();
return true;
}
@@ -483,16 +485,11 @@ bool DocumentBroker::autoSave(const bool force, const size_t waitTimeoutMs, std:
}
else if (_isModified)
{
- // Find the most recent activity.
- double inactivityTimeMs = std::numeric_limits<double>::max();
- for (const auto& sessionIt : _sessions)
- {
- inactivityTimeMs = std::min(sessionIt.second->getInactivityMS(), inactivityTimeMs);
- }
-
- const auto timeSinceLastSaveMs = getTimeSinceLastSaveMs();
+ const auto now = std::chrono::steady_clock::now();
+ const auto inactivityTimeMs = std::chrono::duration_cast<std::chrono::milliseconds>(now - _lastActivityTime).count();
+ const auto timeSinceLastSaveMs = std::chrono::duration_cast<std::chrono::milliseconds>(now - _lastSaveTime).count();
LOG_TRC("Time since last save of docKey [" << _docKey << "] is " << timeSinceLastSaveMs <<
- " ms and most recent activity was " << inactivityTimeMs << "ms ago.");
+ "ms and most recent activity was " << inactivityTimeMs << "ms ago.");
// Either we've been idle long enough, or it's auto-save time.
if (inactivityTimeMs >= IdleSaveDurationMs ||
@@ -1089,7 +1086,7 @@ void DocumentBroker::closeDocument(const std::string& reason)
void DocumentBroker::updateLastActivityTime()
{
- _lastActivity = std::chrono::steady_clock::now();
+ _lastActivityTime = std::chrono::steady_clock::now();
Admin::instance().updateLastActivityTime(_docKey);
}
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 54eb3be..0c2457a 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -226,13 +226,6 @@ public:
return _sessions.size();
}
- /// @eturn the time in milliseconds since last save.
- double getTimeSinceLastSaveMs() const
- {
- const auto duration = (std::chrono::steady_clock::now() - _lastSaveTime);
- return std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
- }
-
std::string getJailRoot() const;
/// Add a new session. Returns the new number of sessions.
@@ -303,7 +296,7 @@ public:
std::size_t getIdleTimeSecs() const
{
- const auto duration = (std::chrono::steady_clock::now() - _lastActivity);
+ const auto duration = (std::chrono::steady_clock::now() - _lastActivityTime);
return std::chrono::duration_cast<std::chrono::seconds>(duration).count();
}
@@ -326,8 +319,15 @@ private:
Poco::URI _uriJailed;
std::string _jailId;
std::string _filename;
+
+ /// The last time we tried saving, regardless of whether the
+ /// document was modified and saved or not.
std::chrono::steady_clock::time_point _lastSaveTime;
+
+ /// The document's last-modified time on storage.
Poco::Timestamp _documentLastModifiedTime;
+
+ /// The jailed file last-modified time.
Poco::Timestamp _lastFileModifiedTime;
std::map<std::string, std::shared_ptr<ClientSession> > _sessions;
std::unique_ptr<StorageBase> _storage;
@@ -350,7 +350,7 @@ private:
int _debugRenderedTileCount;
- std::chrono::steady_clock::time_point _lastActivity;
+ std::chrono::steady_clock::time_point _lastActivityTime;
static constexpr auto IdleSaveDurationMs = 30 * 1000;
static constexpr auto AutoSaveDurationMs = 300 * 1000;
More information about the Libreoffice-commits
mailing list