History

Remove deferred script loading logic

Clement committed 7 years ago

Commit 77232611 parent 2dcfea52 files · +0 −118Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+0−115
@@ -2061,68 +2061,6 @@ bool ScriptEngine::hasEntityScriptDetails(const EntityItemID& entityID) const { · 2060 unmodified lines
20612061 return _entityScripts.contains(entityID);
20622062 }
20632063
2064−const static EntityItemID BAD_SCRIPT_UUID_PLACEHOLDER { "{20170224-dead-face-0000-cee000021114}" };
2065−
2066−void ScriptEngine::processDeferredEntityLoads(const QString& entityScript, const EntityItemID& leaderID) {
2067− QList<DeferredLoadEntity> retryLoads;
2068− QMutableListIterator<DeferredLoadEntity> i(_deferredEntityLoads);
2069− while (i.hasNext()) {
2070− auto retry = i.next();
2071− if (retry.entityScript == entityScript) {
2072− retryLoads << retry;
2073− i.remove();
2074− }
2075− }
2076− foreach(DeferredLoadEntity retry, retryLoads) {
2077− // check whether entity was since been deleted
2078−
2079− EntityScriptDetails details;
2080− if (!getEntityScriptDetails(retry.entityID, details)) {
2081− qCDebug(scriptengine) << "processDeferredEntityLoads -- entity details gone (entity deleted?)"
2082− << retry.entityID;
2083− continue;
2084− }
2085−
2086− // check whether entity has since been unloaded or otherwise errored-out
2087− if (details.status != EntityScriptStatus::PENDING) {
2088− qCDebug(scriptengine) << "processDeferredEntityLoads -- entity status no longer PENDING; "
2089− << retry.entityID << details.status;
2090− continue;
2091− }
2092−
2093− // propagate leader's failure reasons to the pending entity
2094− EntityScriptDetails leaderDetails;
2095− {
2096− QWriteLocker locker { &_entityScriptsLock };
2097− leaderDetails = _entityScripts[leaderID];
2098− }
2099− if (leaderDetails.status != EntityScriptStatus::RUNNING) {
2100− qCDebug(scriptengine) << QString("... pending load of %1 cancelled (leader: %2 status: %3)")
2101− .arg(retry.entityID.toString()).arg(leaderID.toString()).arg(leaderDetails.status);
2102−
2103− auto extraDetail = QString("\n(propagated from %1)").arg(leaderID.toString());
2104− if (leaderDetails.status == EntityScriptStatus::ERROR_LOADING_SCRIPT ||
2105− leaderDetails.status == EntityScriptStatus::ERROR_RUNNING_SCRIPT) {
2106− // propagate same error so User doesn't have to hunt down stampede's leader
2107− updateEntityScriptStatus(retry.entityID, leaderDetails.status, leaderDetails.errorInfo + extraDetail);
2108− } else {
2109− // the leader Entity somehow ended up in some other state (rapid-fire delete or unload could cause)
2110− updateEntityScriptStatus(retry.entityID, EntityScriptStatus::ERROR_LOADING_SCRIPT,
2111− "A previous Entity failed to load using this script URL; reload to try again." + extraDetail);
2112− }
2113− continue;
2114− }
2115−
2116− if (_occupiedScriptURLs.contains(retry.entityScript)) {
2117− qCWarning(scriptengine) << "--- SHOULD NOT HAPPEN -- recursive call into processDeferredEntityLoads" << retry.entityScript;
2118− continue;
2119− }
2120−
2121− // if we made it here then the leading entity was successful so proceed with normal load
2122− loadEntityScript(retry.entityID, retry.entityScript, false);
2123− }
2124−}
2125−
21262064 void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& entityScript, bool forceRedownload) {
21272065 if (QThread::currentThread() != thread()) {
21282066 QMetaObject::invokeMethod(this, "loadEntityScript",
@@ -2147,40 +2085,6 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& · 18 unmodified lines
21472085 updateEntityScriptStatus(entityID, EntityScriptStatus::PENDING, "...pending...");
21482086 }
21492087
2150− // This "occupied" approach allows multiple Entities to boot from the same script URL while still taking
2151− // full advantage of cacheable require modules. This only affects Entities literally coming in back-to-back
2152− // before the first one has time to finish loading.
2153− if (_occupiedScriptURLs.contains(entityScript)) {
2154− auto currentEntityID = _occupiedScriptURLs[entityScript];
2155− if (currentEntityID == BAD_SCRIPT_UUID_PLACEHOLDER) {
2156− if (forceRedownload) {
2157− // script was previously marked unusable, but we're reloading so reset it
2158− _occupiedScriptURLs.remove(entityScript);
2159− } else {
2160− // since not reloading, assume that the exact same input would produce the exact same output again
2161− // note: this state gets reset with "reload all scripts," leaving/returning to a Domain, clear cache, etc.
2162−#ifdef DEBUG_ENTITY_STATES
2163− qCDebug(scriptengine) << QString("loadEntityScript.cancelled entity: %1 (previous script failure)")
2164− .arg(entityID.toString());
2165−#endif
2166− updateEntityScriptStatus(entityID, EntityScriptStatus::ERROR_LOADING_SCRIPT,
2167− "A previous Entity failed to load using this script URL; reload to try again.");
2168− return;
2169− }
2170− } else {
2171− // another entity is busy loading from this script URL so wait for them to finish
2172−#ifdef DEBUG_ENTITY_STATES
2173− qCDebug(scriptengine) << QString("loadEntityScript.deferring[%0] entity: %1 (waiting on %2 )")
2174− .arg(_deferredEntityLoads.size()).arg(entityID.toString()).arg(currentEntityID.toString());
2175−#endif
2176− _deferredEntityLoads.push_back({ entityID, entityScript });
2177− return;
2178− }
2179− }
2180−
2181− // the scriptURL slot is available; flag as in-use
2182− _occupiedScriptURLs[entityScript] = entityID;
2183−
21842088 #ifdef DEBUG_ENTITY_STATES
21852089 {
21862090 EntityScriptDetails details;
@@ -2223,10 +2127,6 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& · 36 unmodified lines
22232127 qCDebug(scriptengine) << "loadEntityScript.contentAvailable -- aborting";
22242128 #endif
22252129 }
2226− // recheck whether us since may have been set to BAD_SCRIPT_UUID_PLACEHOLDER in entityScriptContentAvailable
2227− if (_occupiedScriptURLs.contains(entityScript) && _occupiedScriptURLs[entityScript] == entityID) {
2228− _occupiedScriptURLs.remove(entityScript);
2229− }
22302130 });
22312131 }, forceRedownload);
22322132 }
@@ -2301,13 +2201,6 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 68 unmodified lines
23012201 newDetails.errorInfo = errorInfo;
23022202 newDetails.status = status;
23032203 setEntityScriptDetails(entityID, newDetails);
2304−
2305−#ifdef DEBUG_ENTITY_STATES
2306− qCDebug(scriptengine) << "entityScriptContentAvailable -- flagging as BAD_SCRIPT_UUID_PLACEHOLDER";
2307−#endif
2308− // flag the original entityScript as unusuable
2309− _occupiedScriptURLs[entityScript] = BAD_SCRIPT_UUID_PLACEHOLDER;
2310− processDeferredEntityLoads(entityScript, entityID);
23112204 };
23122205
23132206 // NETWORK / FILESYSTEM ERRORS
@@ -2441,9 +2334,6 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 127 unmodified lines
24412334 callEntityScriptMethod(entityID, "preload");
24422335
24432336 emit entityScriptPreloadFinished(entityID);
2444−
2445− _occupiedScriptURLs.remove(entityScript);
2446− processDeferredEntityLoads(entityScript, entityID);
24472337 }
24482338
24492339 /**jsdoc
@@ -2499,10 +2389,6 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID, bool shouldR · 49 unmodified lines
24992389 }
25002390
25012391 stopAllTimersForEntityScript(entityID);
2502− {
2503− // FIXME: shouldn't have to do this here, but currently something seems to be firing unloads moments after firing initial load requests
2504− processDeferredEntityLoads(scriptText, entityID);
2505− }
25062392 }
25072393 }
25082394
@@ -2532,7 +2418,6 @@ void ScriptEngine::unloadAllEntityScripts() { · 23 unmodified lines
25322418 _entityScripts.clear();
25332419 }
25342420 emit entityScriptDetailsUpdated();
2535− _occupiedScriptURLs.clear();
25362421
25372422 #ifdef DEBUG_ENGINE_STATE
25382423 _debugDump(

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t