[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue Apr 26 10:40:25 UTC 2016


 loolwsd/DocumentBroker.cpp |   26 +++++++++++++++++++-------
 loolwsd/DocumentBroker.hpp |    1 +
 2 files changed, 20 insertions(+), 7 deletions(-)

New commits:
commit d4aa547d3c185a7e2868652fa902549c280cfd2b
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon Apr 25 20:44:24 2016 -0400

    loolwsd: avoid persisting excessively
    
    When multiple users have a document open,
    save notficiations are broadcast to all.
    Each session then tries to store the document
    to the Storage when only the first should suffice.
    
    A new file modified-time member tracks the file's
    timestamp and only persists when it changes,
    thereby avoid excessive stores.
    
    Change-Id: I138f1aa812963a2120a1fcac763dfacccc542c1a
    Reviewed-on: https://gerrit.libreoffice.org/24381
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index fc7d887..e7fb11f 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -127,17 +127,20 @@ bool DocumentBroker::load(const std::string& jailId)
 
     Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot);
 
-    auto storage = StorageBase::create("", "", _uriPublic);
+    auto storage = StorageBase::create(jailRoot, jailPath.toString(), _uriPublic);
     if (storage)
     {
         const auto fileInfo = storage->getFileInfo(_uriPublic);
-        _tileCache.reset(new TileCache(_uriPublic.toString(), fileInfo._modifiedTime, _cacheRoot));
         _filename = fileInfo._filename;
-        _storage = StorageBase::create(jailRoot, jailPath.toString(), _uriPublic);
 
-        const auto localPath = _storage->loadStorageFileToLocal();
+        const auto localPath = storage->loadStorageFileToLocal();
         _uriJailed = Poco::URI(Poco::URI("file://"), localPath);
 
+        // Use the local temp file's timestamp.
+        _lastFileModifiedTime = Poco::File(storage->getLocalRootPath()).getLastModified();
+        _tileCache.reset(new TileCache(_uriPublic.toString(), _lastFileModifiedTime, _cacheRoot));
+
+        _storage.reset(storage.release());
         return true;
     }
 
@@ -149,18 +152,27 @@ bool DocumentBroker::save()
     std::unique_lock<std::mutex> lock(_saveMutex);
 
     const auto uri = _uriPublic.toString();
+    const auto newFileModifiedTime = Poco::File(_storage->getLocalRootPath()).getLastModified();
+    if (newFileModifiedTime == _lastFileModifiedTime)
+    {
+        // Nothing to do.
+        Log::debug("Skipping unnecessary saving to URI [" + uri + "].");
+        return true;
+    }
+
     Log::debug("Saving to URI [" + uri + "].");
 
     assert(_storage && _tileCache);
     if (_storage->saveLocalFileToStorage())
     {
         _isModified = false;
-        _lastSaveTime = std::chrono::steady_clock::now();
         _tileCache->setUnsavedChanges(false);
+        const auto fileInfo = _storage->getFileInfo(_uriPublic);
+        _lastFileModifiedTime = newFileModifiedTime;
+        _tileCache->saveLastModified(_lastFileModifiedTime);
+        _lastSaveTime = std::chrono::steady_clock::now();
         Log::debug("Saved to URI [" + uri + "] and updated tile cache.");
         _saveCV.notify_all();
-        const auto fileInfo = _storage->getFileInfo(_uriPublic);
-        _tileCache->saveLastModified(fileInfo._modifiedTime);
         return true;
     }
 
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 0abf3f1..1ef6df0 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -213,6 +213,7 @@ private:
     std::string _jailId;
     std::string _filename;
     std::chrono::steady_clock::time_point _lastSaveTime;
+    Poco::Timestamp _lastFileModifiedTime;
     std::map<std::string, std::shared_ptr<MasterProcessSession>> _sessions;
     std::unique_ptr<StorageBase> _storage;
     std::unique_ptr<TileCache> _tileCache;


More information about the Libreoffice-commits mailing list