From decb94b719311dba73338538f73216214c6fc37b Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 13 Oct 2016 14:01:45 -0700 Subject: [PATCH 1/2] Update ScriptCache to clear ATP assets when disconnected from a domain --- interface/src/Application.cpp | 4 ++++ libraries/script-engine/src/ScriptCache.cpp | 13 +++++++++++++ libraries/script-engine/src/ScriptCache.h | 1 + 3 files changed, 18 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 80e444462f..5658ed8b64 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -668,6 +668,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails())); connect(&domainHandler, &DomainHandler::domainConnectionRefused, this, &Application::domainConnectionRefused); + // We could clear ATP assets only when changing domains, but it's possible that the domain you are connected + // to has gone down and switched to a new content set, so when you reconnect the cached ATP assets will no longer be valid. + connect(&domainHandler, &DomainHandler::disconnectedFromDomain, DependencyManager::get().data(), &ScriptCache::clearATPScriptsFromCache); + // update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * MSECS_PER_SECOND; diff --git a/libraries/script-engine/src/ScriptCache.cpp b/libraries/script-engine/src/ScriptCache.cpp index e9f20b5164..a2a6a9ecf1 100644 --- a/libraries/script-engine/src/ScriptCache.cpp +++ b/libraries/script-engine/src/ScriptCache.cpp @@ -36,6 +36,19 @@ void ScriptCache::clearCache() { _scriptCache.clear(); } +void ScriptCache::clearATPScriptsFromCache() { + Lock lock(_containerLock); + qDebug(scriptengine) << "Clearing ATP scripts from ScriptCache"; + for (auto it = _scriptCache.begin(); it != _scriptCache.end();) { + if (it.key().scheme() == "atp") { + qDebug(scriptengine) << "Removing: " << it.key(); + it = _scriptCache.erase(it); + } else { + ++it; + } + } +} + QString ScriptCache::getScript(const QUrl& unnormalizedURL, ScriptUser* scriptUser, bool& isPending, bool reload) { QUrl url = ResourceManager::normalizeURL(unnormalizedURL); QString scriptContents; diff --git a/libraries/script-engine/src/ScriptCache.h b/libraries/script-engine/src/ScriptCache.h index 17ba5c4b0a..5aac62b08b 100644 --- a/libraries/script-engine/src/ScriptCache.h +++ b/libraries/script-engine/src/ScriptCache.h @@ -39,6 +39,7 @@ class ScriptCache : public QObject, public Dependency { public: void clearCache(); + Q_INVOKABLE void clearATPScriptsFromCache(); void getScriptContents(const QString& scriptOrURL, contentAvailableCallback contentAvailable, bool forceDownload = false); From 7626f49ddc964b4a1d69609f87fd4280f33b35ee Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 13 Oct 2016 15:43:28 -0700 Subject: [PATCH 2/2] Replace qDebug with qCDebug in ScriptCache --- libraries/script-engine/src/ScriptCache.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/script-engine/src/ScriptCache.cpp b/libraries/script-engine/src/ScriptCache.cpp index a2a6a9ecf1..96e3d7e914 100644 --- a/libraries/script-engine/src/ScriptCache.cpp +++ b/libraries/script-engine/src/ScriptCache.cpp @@ -38,10 +38,10 @@ void ScriptCache::clearCache() { void ScriptCache::clearATPScriptsFromCache() { Lock lock(_containerLock); - qDebug(scriptengine) << "Clearing ATP scripts from ScriptCache"; + qCDebug(scriptengine) << "Clearing ATP scripts from ScriptCache"; for (auto it = _scriptCache.begin(); it != _scriptCache.end();) { if (it.key().scheme() == "atp") { - qDebug(scriptengine) << "Removing: " << it.key(); + qCDebug(scriptengine) << "Removing: " << it.key(); it = _scriptCache.erase(it); } else { ++it;