[Pkg-owncloud-commits] [owncloud-client] 02/175: shell_integration on Windows: Avoid too many RETRIEVE_FILE_STATUS following UPDATE_VIEW #3122

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Aug 8 10:36:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 0d5d2c578dca8318b86e0922aafdbac3f5a60fdf
Author: Jocelyn Turcotte <jturcotte at woboq.com>
Date:   Tue May 5 11:24:01 2015 +0200

    shell_integration on Windows: Avoid too many RETRIEVE_FILE_STATUS following UPDATE_VIEW #3122
    
    Do not request the status of all entries in the cache. Instead force
    explorer to request the ones that it deems necessary by keeping the old
    statuses in a separate dictionary which are only used while the new status
    arrives.
---
 binary                                             |  2 +-
 .../windows/OCUtil/RemotePathChecker.cpp           | 33 +++++++++++++++-------
 .../windows/OCUtil/RemotePathChecker.h             |  1 +
 3 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/binary b/binary
index 1fb9ddf..8b72648 160000
--- a/binary
+++ b/binary
@@ -1 +1 @@
-Subproject commit 1fb9ddfa9a9a1b4dbc447eee10dbed89172d968a
+Subproject commit 8b72648a939580995facefcd5f635388000ab4d1
diff --git a/shell_integration/windows/OCUtil/RemotePathChecker.cpp b/shell_integration/windows/OCUtil/RemotePathChecker.cpp
index 0dda646..e9ed9fd 100644
--- a/shell_integration/windows/OCUtil/RemotePathChecker.cpp
+++ b/shell_integration/windows/OCUtil/RemotePathChecker.cpp
@@ -98,6 +98,8 @@ void RemotePathChecker::workerThreadLoop()
                             ++it;
                         }
                     }
+                    // Assume that we won't need this at this point, UNREGISTER_PATH is rare
+                    _oldCache.clear();
                 }
 				SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH | SHCNF_FLUSHNOWAIT, responsePath.data(), NULL);
             } else if (StringUtil::begins_with(response, wstring(L"STATUS:")) ||
@@ -132,20 +134,25 @@ void RemotePathChecker::workerThreadLoop()
 			}
 			else if (StringUtil::begins_with(response, wstring(L"UPDATE_VIEW"))) {
 				std::unique_lock<std::mutex> lock(_mutex);
-                auto cache = _cache; // Make a copy of the cache under the mutex
+                // Keep the old states to continue having something to display while the new state is
+                // requested from the client, triggered by clearing _cache.
+                _oldCache.insert(_cache.cbegin(), _cache.cend());
+
+                // Swap to make a copy of the cache under the mutex and clear the one stored.
+                std::unordered_map<std::wstring, FileState> cache;
+                swap(cache, _cache);
                 lock.unlock();
-				// Request a status for all the items in the cache.
-				for (auto it = cache.begin(); it != cache.end(); ++it) {
-					if (!socket.SendMsg(wstring(L"RETRIEVE_FILE_STATUS:" + it->first + L'\n').data())) {
-						break;
-					}
-				}
-			}
+                // Let explorer know about the invalidated cache entries, it will re-request the ones it needs.
+                for (auto it = cache.begin(); it != cache.end(); ++it) {
+                    SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH | SHCNF_FLUSHNOWAIT, it->first.data(), NULL);
+                }
+            }
 		}
 
 		if (socket.Event() == INVALID_HANDLE_VALUE) {
 			std::unique_lock<std::mutex> lock(_mutex);
 			_cache.clear();
+            _oldCache.clear();
 			_watchedDirectories.clear();
 			_connected = connected = false;
 		}
@@ -198,11 +205,17 @@ bool RemotePathChecker::IsMonitoredPath(const wchar_t* filePath, int* state)
         return true;
     }
 
+    // Re-request the status while we display what we have in _oldCache
     _pending.push(filePath);
+
+    it = _oldCache.find(path);
+    bool foundInOldCache = it != _oldCache.end();
+    if (foundInOldCache)
+        *state = it->second;
+
     lock.unlock();
     SetEvent(_newQueries);
-    return false;
-
+    return foundInOldCache;
 }
 
 RemotePathChecker::FileState RemotePathChecker::_StrToFileState(const std::wstring &str)
diff --git a/shell_integration/windows/OCUtil/RemotePathChecker.h b/shell_integration/windows/OCUtil/RemotePathChecker.h
index 7d7decd..8df2c35 100644
--- a/shell_integration/windows/OCUtil/RemotePathChecker.h
+++ b/shell_integration/windows/OCUtil/RemotePathChecker.h
@@ -52,6 +52,7 @@ private:
     std::queue<std::wstring> _pending;
 
     std::unordered_map<std::wstring, FileState> _cache;
+    std::unordered_map<std::wstring, FileState> _oldCache;
     std::vector<std::wstring> _watchedDirectories;
     bool _connected;
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list