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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue May 10 03:44:51 UTC 2016


 loolwsd/DocumentBroker.cpp |   22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

New commits:
commit ca22a79034cbf996f788303633297c9c11096143
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon May 9 21:15:09 2016 -0400

    loolwsd: simplify detection of file modification
    
    To avoid persisting the same document many times over
    we check the jailed file timestamp. This logic
    doesn't need to be more complex than simply invalidating
    the last timestamp upon issuing .uno:Save and setting
    it to the file's actual timestamp upon persisting.
    
    Change-Id: I4afdf8da93fed438d4cbcd6de8dc14d52172ac9c
    Reviewed-on: https://gerrit.libreoffice.org/24811
    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 7b1af96..764c6ab 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -177,23 +177,16 @@ bool DocumentBroker::save()
 
     const auto uri = _uriPublic.toString();
 
-    // If we aren't potentially destroying just yet, and the file has been
-    // modified within the past 10 seconds, skip saving.
-    //
-    // FIXME this is because currently the ChildProcessSession broadcasts the
-    // unocommandresult, so we get called several times here, and have no real
-    // possibility to distinguish who was the 1st caller.
-    // The refactor to un-thread the ChildProcessSession, and move the
-    // broadcasting up in the hierarchy (so that we can 'sniff' the
-    // unocommandresult for .uno:Save at the place where it appears just once)
-    // is planned post-release.
+    // If we aren't potentially destroying just yet, and the file
+    // timestamp hasn't changed, skip saving.
     const auto newFileModifiedTime = Poco::File(_storage->getLocalRootPath()).getLastModified();
-    const auto elapsed = newFileModifiedTime - _lastFileModifiedTime;
-    if (!canDestroy() && std::abs(elapsed) < 10 * 1000)
+    if (!isMarkedToDestroy() && newFileModifiedTime == _lastFileModifiedTime)
     {
         // Nothing to do.
         Log::debug() << "Skipping unnecessary saving to URI [" << uri
-                     << "]. File last modified " << elapsed << " ms ago." << Log::end;
+                     << "]. File last modified "
+                     << _lastFileModifiedTime.elapsed() / 1000000
+                     << " seconds ago." << Log::end;
         return true;
     }
 
@@ -288,6 +281,9 @@ bool DocumentBroker::sendUnoSave()
             auto queue = sessionIt.second->getQueue();
             if (queue)
             {
+                // Invalidate the timestamp to force persisting.
+                _lastFileModifiedTime.fromEpochTime(0);
+
                 queue->put("uno .uno:Save");
 
                 // Set calc cell mode back to edit mode


More information about the Libreoffice-commits mailing list