[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - loolwsd.xml.in wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp wsd/TileCache.cpp wsd/TileCache.hpp

Marco Cecchetti marco.cecchetti at collabora.com
Wed Apr 12 18:09:59 UTC 2017


 loolwsd.xml.in         |    2 ++
 wsd/DocumentBroker.cpp |    4 ++++
 wsd/LOOLWSD.cpp        |    4 ++++
 wsd/LOOLWSD.hpp        |    1 +
 wsd/TileCache.cpp      |    9 +++++++--
 wsd/TileCache.hpp      |    3 +++
 6 files changed, 21 insertions(+), 2 deletions(-)

New commits:
commit acfbdfa3d59d3d52feae0f711f9d4af3fd71cd66
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Wed Apr 12 12:32:59 2017 +0200

    wsd - implemented an option to clean cache on doc close
    
    Includes also the following commit:
    
    Clean the cache even when the document was not modified.
    
    And rename the option, to match better the existing tile cache setting.
    
    Change-Id: I0bdb373efb93546527a168df2ed1c75539e95fe4

diff --git a/loolwsd.xml.in b/loolwsd.xml.in
index 511b5479..5640d08f 100644
--- a/loolwsd.xml.in
+++ b/loolwsd.xml.in
@@ -77,6 +77,8 @@
         </webdav>
     </storage>
 
+    <tile_cache_persistent desc="Should the tiles persist between two editing sessions of the given document?" type="bool" default="true">true</tile_cache_persistent>
+
     <admin_console desc="Web admin console settings.">
         <username desc="The username of the admin console. Must be set."></username>
         <password desc="The password of the admin console. Must be set."></password>
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index e041db70..3cac2e70 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1198,6 +1198,10 @@ void DocumentBroker::destroyIfLastEditor(const std::string& id)
     _markToDestroy = (_sessions.size() <= 1);
     LOG_DBG("startDestroy on session [" << id << "] on docKey [" << _docKey <<
             "], markToDestroy: " << _markToDestroy << ", lastEditableSession: " << _lastEditableSession);
+
+    // Remove all tiles related to this document from the cache.
+    if (_markToDestroy && !LOOLWSD::TileCachePersistent)
+        _tileCache->completeCleanup();
 }
 
 void DocumentBroker::setModified(const bool value)
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 57c63523..9d3c62fe 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -553,6 +553,7 @@ static std::string UnitTestLibrary;
 
 unsigned int LOOLWSD::NumPreSpawnedChildren = 0;
 std::atomic<unsigned> LOOLWSD::NumConnections;
+bool LOOLWSD::TileCachePersistent = true;
 std::unique_ptr<TraceFileWriter> LOOLWSD::TraceDumper;
 
 /// This thread polls basic web serving, and handling of
@@ -610,6 +611,7 @@ void LOOLWSD::initialize(Application& self)
     // Add default values of new entries here.
     static const std::map<std::string, std::string> DefAppConfig
         = { { "tile_cache_path", LOOLWSD_CACHEDIR },
+            { "tile_cache_persistent", "true" },
             { "sys_template_path", "systemplate" },
             { "lo_template_path", LO_PATH },
             { "child_root_path", "jails" },
@@ -762,6 +764,8 @@ void LOOLWSD::initialize(Application& self)
 
     LOOLWSD::NumConnections = 0;
 
+    TileCachePersistent = getConfigValue<bool>(conf, "tile_cache_persistent", true);
+
     // Command Tracing.
     if (getConfigValue<bool>(conf, "trace[@enable]", false))
     {
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 072a4a88..72c3a9a1 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -53,6 +53,7 @@ public:
     static std::string FileServerRoot;
     static std::string LOKitVersion;
     static std::atomic<unsigned> NumConnections;
+    static bool TileCachePersistent;
     static std::unique_ptr<TraceFileWriter> TraceDumper;
 
     /// Flag to shutdown the server.
diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp
index b744eded..ff30710f 100644
--- a/wsd/TileCache.cpp
+++ b/wsd/TileCache.cpp
@@ -63,8 +63,7 @@ TileCache::TileCache(const std::string& docURL,
          getTextFile("unsaved.txt", unsaved)))
     {
         // Document changed externally or modifications were not saved after all. Cache not useful.
-        FileUtil::removeFile(_cacheDir, true);
-        LOG_INF("Completely cleared tile cache: " << _cacheDir);
+        completeCleanup();
     }
 
     File(_cacheDir).createDirectories();
@@ -77,6 +76,12 @@ TileCache::~TileCache()
     LOG_INF("~TileCache dtor for uri [" << _docURL << "].");
 }
 
+void TileCache::completeCleanup() const
+{
+    FileUtil::removeFile(_cacheDir, true);
+    LOG_INF("Completely cleared tile cache: " << _cacheDir);
+}
+
 /// Tracks the rendering of a given tile
 /// to avoid duplication and help clock
 /// rendering latency.
diff --git a/wsd/TileCache.hpp b/wsd/TileCache.hpp
index 96b5a5b3..9f86cc72 100644
--- a/wsd/TileCache.hpp
+++ b/wsd/TileCache.hpp
@@ -36,6 +36,9 @@ public:
     TileCache(const std::string& docURL, const Poco::Timestamp& modifiedTime, const std::string& cacheDir);
     ~TileCache();
 
+    /// Remove the entire cache directory.
+    void completeCleanup() const;
+
     TileCache(const TileCache&) = delete;
 
     /// Subscribes if no subscription exists and returns the version number.


More information about the Libreoffice-commits mailing list