diff options
Diffstat (limited to 'indra/newview/llinventorymodelbackgroundfetch.cpp')
-rw-r--r-- | indra/newview/llinventorymodelbackgroundfetch.cpp | 263 |
1 files changed, 149 insertions, 114 deletions
diff --git a/indra/newview/llinventorymodelbackgroundfetch.cpp b/indra/newview/llinventorymodelbackgroundfetch.cpp index cfbc2c3e05..ce44e37017 100644 --- a/indra/newview/llinventorymodelbackgroundfetch.cpp +++ b/indra/newview/llinventorymodelbackgroundfetch.cpp @@ -33,39 +33,23 @@ #include "llviewerprecompiledheaders.h" #include "llinventorymodelbackgroundfetch.h" -// Seraph clean this up #include "llagent.h" +#include "llappviewer.h" +#include "llcallbacklist.h" #include "llinventorypanel.h" #include "llviewercontrol.h" #include "llviewermessage.h" -#include "llviewerwindow.h" -#include "llappviewer.h" #include "llviewerregion.h" -#include "llcallbacklist.h" +#include "llviewerwindow.h" const F32 MAX_TIME_FOR_SINGLE_FETCH = 10.f; const S32 MAX_FETCH_RETRIES = 10; -// RN: for some reason, using std::queue in the header file confuses the compiler which thinks it's an xmlrpc_queue -static std::deque<LLUUID> sFetchQueue; -bool fetchQueueContainsNoDescendentsOf(const LLUUID& cat_id) -{ - for (std::deque<LLUUID>::iterator it = sFetchQueue.begin(); - it != sFetchQueue.end(); ++it) - { - const LLUUID& fetch_id = *it; - if (gInventory.isObjectDescendentOf(fetch_id, cat_id)) - return false; - } - return true; -} - - LLInventoryModelBackgroundFetch::LLInventoryModelBackgroundFetch() : mBackgroundFetchActive(FALSE), mAllFoldersFetched(FALSE), - mInventoryFetchStarted(FALSE), - mLibraryFetchStarted(FALSE), + mRecursiveInventoryFetchStarted(FALSE), + mRecursiveLibraryFetchStarted(FALSE), mNumFetchRetries(0), mMinTimeBetweenFetches(0.3f), mMaxTimeBetweenFetches(10.f), @@ -78,86 +62,88 @@ LLInventoryModelBackgroundFetch::~LLInventoryModelBackgroundFetch() { } -bool LLInventoryModelBackgroundFetch::isBulkFetchProcessingComplete() +bool LLInventoryModelBackgroundFetch::isBulkFetchProcessingComplete() const { - return sFetchQueue.empty() && mBulkFetchCount<=0; + return mFetchQueue.empty() && mBulkFetchCount<=0; } -bool LLInventoryModelBackgroundFetch::libraryFetchStarted() +bool LLInventoryModelBackgroundFetch::libraryFetchStarted() const { - return mLibraryFetchStarted; + return mRecursiveLibraryFetchStarted; } -bool LLInventoryModelBackgroundFetch::libraryFetchCompleted() +bool LLInventoryModelBackgroundFetch::libraryFetchCompleted() const { return libraryFetchStarted() && fetchQueueContainsNoDescendentsOf(gInventory.getLibraryRootFolderID()); } -bool LLInventoryModelBackgroundFetch::libraryFetchInProgress() +bool LLInventoryModelBackgroundFetch::libraryFetchInProgress() const { return libraryFetchStarted() && !libraryFetchCompleted(); } -bool LLInventoryModelBackgroundFetch::inventoryFetchStarted() +bool LLInventoryModelBackgroundFetch::inventoryFetchStarted() const { - return mInventoryFetchStarted; + return mRecursiveInventoryFetchStarted; } -bool LLInventoryModelBackgroundFetch::inventoryFetchCompleted() +bool LLInventoryModelBackgroundFetch::inventoryFetchCompleted() const { return inventoryFetchStarted() && fetchQueueContainsNoDescendentsOf(gInventory.getRootFolderID()); } -bool LLInventoryModelBackgroundFetch::inventoryFetchInProgress() +bool LLInventoryModelBackgroundFetch::inventoryFetchInProgress() const { return inventoryFetchStarted() && !inventoryFetchCompleted(); } -bool LLInventoryModelBackgroundFetch::isEverythingFetched() +bool LLInventoryModelBackgroundFetch::isEverythingFetched() const { return mAllFoldersFetched; } -BOOL LLInventoryModelBackgroundFetch::backgroundFetchActive() +BOOL LLInventoryModelBackgroundFetch::backgroundFetchActive() const { return mBackgroundFetchActive; } -void LLInventoryModelBackgroundFetch::start(const LLUUID& cat_id) +void LLInventoryModelBackgroundFetch::start(const LLUUID& cat_id, BOOL recursive) { if (!mAllFoldersFetched) { + LL_DEBUGS("InventoryFetch") << "Start fetching category: " << cat_id << ", recursive: " << recursive << LL_ENDL; + mBackgroundFetchActive = TRUE; if (cat_id.isNull()) { - if (!mInventoryFetchStarted) + if (!mRecursiveInventoryFetchStarted) { - mInventoryFetchStarted = TRUE; - sFetchQueue.push_back(gInventory.getRootFolderID()); + mRecursiveInventoryFetchStarted |= recursive; + mFetchQueue.push_back(FetchQueueInfo(gInventory.getRootFolderID(), recursive)); gIdleCallbacks.addFunction(&LLInventoryModelBackgroundFetch::backgroundFetchCB, NULL); } - if (!mLibraryFetchStarted) + if (!mRecursiveLibraryFetchStarted) { - mLibraryFetchStarted = TRUE; - sFetchQueue.push_back(gInventory.getLibraryRootFolderID()); + mRecursiveLibraryFetchStarted |= recursive; + mFetchQueue.push_back(FetchQueueInfo(gInventory.getLibraryRootFolderID(), recursive)); gIdleCallbacks.addFunction(&LLInventoryModelBackgroundFetch::backgroundFetchCB, NULL); } } else { - // specific folder requests go to front of queue - if (sFetchQueue.empty() || sFetchQueue.front() != cat_id) + // Specific folder requests go to front of queue. + if (mFetchQueue.empty() || mFetchQueue.front().mCatUUID != cat_id) { - sFetchQueue.push_front(cat_id); + mFetchQueue.push_front(FetchQueueInfo(cat_id, recursive)); gIdleCallbacks.addFunction(&LLInventoryModelBackgroundFetch::backgroundFetchCB, NULL); } if (cat_id == gInventory.getLibraryRootFolderID()) { - mLibraryFetchStarted = TRUE; + mRecursiveLibraryFetchStarted |= recursive; } if (cat_id == gInventory.getRootFolderID()) { - mInventoryFetchStarted = TRUE; + mRecursiveInventoryFetchStarted |= recursive; } } } @@ -166,7 +152,7 @@ void LLInventoryModelBackgroundFetch::start(const LLUUID& cat_id) void LLInventoryModelBackgroundFetch::findLostItems() { mBackgroundFetchActive = TRUE; - sFetchQueue.push_back(LLUUID::null); + mFetchQueue.push_back(FetchQueueInfo(LLUUID::null, TRUE)); gIdleCallbacks.addFunction(&LLInventoryModelBackgroundFetch::backgroundFetchCB, NULL); } @@ -183,8 +169,8 @@ void LLInventoryModelBackgroundFetch::stopBackgroundFetch() void LLInventoryModelBackgroundFetch::setAllFoldersFetched() { - if (mInventoryFetchStarted && - mLibraryFetchStarted) + if (mRecursiveInventoryFetchStarted && + mRecursiveLibraryFetchStarted) { mAllFoldersFetched = TRUE; } @@ -200,7 +186,7 @@ void LLInventoryModelBackgroundFetch::backgroundFetch() { if (mBackgroundFetchActive && gAgent.getRegion()) { - //If we'll be using the capability, we'll be sending batches and the background thing isn't as important. + // If we'll be using the capability, we'll be sending batches and the background thing isn't as important. std::string url = gAgent.getRegion()->getCapability("WebFetchInventoryDescendents"); if (!url.empty()) { @@ -208,9 +194,13 @@ void LLInventoryModelBackgroundFetch::backgroundFetch() return; } - //DEPRECATED OLD CODE FOLLOWS. - // no more categories to fetch, stop fetch process - if (sFetchQueue.empty()) +#if 1 + //-------------------------------------------------------------------------------- + // DEPRECATED OLD CODE + // + + // No more categories to fetch, stop fetch process. + if (mFetchQueue.empty()) { llinfos << "Inventory fetch completed" << llendl; @@ -222,41 +212,42 @@ void LLInventoryModelBackgroundFetch::backgroundFetch() F32 slow_fetch_time = lerp(mMinTimeBetweenFetches, mMaxTimeBetweenFetches, 0.5f); if (mTimelyFetchPending && mFetchTimer.getElapsedTimeF32() > slow_fetch_time) { - // double timeouts on failure + // Double timeouts on failure. mMinTimeBetweenFetches = llmin(mMinTimeBetweenFetches * 2.f, 10.f); mMaxTimeBetweenFetches = llmin(mMaxTimeBetweenFetches * 2.f, 120.f); llinfos << "Inventory fetch times grown to (" << mMinTimeBetweenFetches << ", " << mMaxTimeBetweenFetches << ")" << llendl; - // fetch is no longer considered "timely" although we will wait for full time-out + // fetch is no longer considered "timely" although we will wait for full time-out. mTimelyFetchPending = FALSE; } while(1) { - if (sFetchQueue.empty()) + if (mFetchQueue.empty()) { break; } if(gDisconnected) { - // just bail if we are disconnected. + // Just bail if we are disconnected. break; } - LLViewerInventoryCategory* cat = gInventory.getCategory(sFetchQueue.front()); + const FetchQueueInfo info = mFetchQueue.front(); + LLViewerInventoryCategory* cat = gInventory.getCategory(info.mCatUUID); - // category has been deleted, remove from queue. + // Category has been deleted, remove from queue. if (!cat) { - sFetchQueue.pop_front(); + mFetchQueue.pop_front(); continue; } if (mFetchTimer.getElapsedTimeF32() > mMinTimeBetweenFetches && LLViewerInventoryCategory::VERSION_UNKNOWN == cat->getVersion()) { - // category exists but has no children yet, fetch the descendants - // for now, just request every time and rely on retry timer to throttle + // Category exists but has no children yet, fetch the descendants + // for now, just request every time and rely on retry timer to throttle. if (cat->fetch()) { mFetchTimer.reset(); @@ -270,13 +261,13 @@ void LLInventoryModelBackgroundFetch::backgroundFetch() break; } } - // do I have all my children? - else if (gInventory.isCategoryComplete(sFetchQueue.front())) + // Do I have all my children? + else if (gInventory.isCategoryComplete(info.mCatUUID)) { - // finished with this category, remove from queue - sFetchQueue.pop_front(); + // Finished with this category, remove from queue. + mFetchQueue.pop_front(); - // add all children to queue + // Add all children to queue. LLInventoryModel::cat_array_t* categories; LLInventoryModel::item_array_t* items; gInventory.getDirectDescendentsOf(cat->getUUID(), categories, items); @@ -284,13 +275,13 @@ void LLInventoryModelBackgroundFetch::backgroundFetch() it != categories->end(); ++it) { - sFetchQueue.push_back((*it)->getUUID()); + mFetchQueue.push_back(FetchQueueInfo((*it)->getUUID(),info.mRecursive)); } - // we received a response in less than the fast time + // We received a response in less than the fast time. if (mTimelyFetchPending && mFetchTimer.getElapsedTimeF32() < fast_fetch_time) { - // shrink timeouts based on success + // Shrink timeouts based on success. mMinTimeBetweenFetches = llmax(mMinTimeBetweenFetches * 0.8f, 0.3f); mMaxTimeBetweenFetches = llmax(mMaxTimeBetweenFetches * 0.8f, 10.f); //llinfos << "Inventory fetch times shrunk to (" << mMinTimeBetweenFetches << ", " << mMaxTimeBetweenFetches << ")" << llendl; @@ -301,24 +292,28 @@ void LLInventoryModelBackgroundFetch::backgroundFetch() } else if (mFetchTimer.getElapsedTimeF32() > mMaxTimeBetweenFetches) { - // received first packet, but our num descendants does not match db's num descendants - // so try again later - LLUUID fetch_id = sFetchQueue.front(); - sFetchQueue.pop_front(); + // Received first packet, but our num descendants does not match db's num descendants + // so try again later. + mFetchQueue.pop_front(); if (mNumFetchRetries++ < MAX_FETCH_RETRIES) { // push on back of queue - sFetchQueue.push_back(fetch_id); + mFetchQueue.push_back(info); } mTimelyFetchPending = FALSE; mFetchTimer.reset(); break; } - // not enough time has elapsed to do a new fetch + // Not enough time has elapsed to do a new fetch break; } + + // + // DEPRECATED OLD CODE + //-------------------------------------------------------------------------------- +#endif } } @@ -334,20 +329,25 @@ void LLInventoryModelBackgroundFetch::incrBulkFetch(S16 fetching) class LLInventoryModelFetchDescendentsResponder: public LLHTTPClient::Responder { - public: - LLInventoryModelFetchDescendentsResponder(const LLSD& request_sd) : mRequestSD(request_sd) {}; - //LLInventoryModelFetchDescendentsResponder() {}; - void result(const LLSD& content); - void error(U32 status, const std::string& reason); - public: - typedef std::vector<LLViewerInventoryCategory*> folder_ref_t; - protected: - LLSD mRequestSD; +public: + LLInventoryModelFetchDescendentsResponder(const LLSD& request_sd, uuid_vec_t recursive_cats) : + mRequestSD(request_sd), + mRecursiveCatUUIDs(recursive_cats) + {}; + //LLInventoryModelFetchDescendentsResponder() {}; + void result(const LLSD& content); + void error(U32 status, const std::string& reason); +protected: + BOOL getIsRecursive(const LLUUID& cat_id) const; +private: + LLSD mRequestSD; + uuid_vec_t mRecursiveCatUUIDs; // hack for storing away which cat fetches are recursive }; -//If we get back a normal response, handle it here -void LLInventoryModelFetchDescendentsResponder::result(const LLSD& content) +// If we get back a normal response, handle it here. +void LLInventoryModelFetchDescendentsResponder::result(const LLSD& content) { + LLInventoryModelBackgroundFetch *fetcher = LLInventoryModelBackgroundFetch::getInstance(); if (content.has("folders")) { @@ -412,11 +412,12 @@ void LLInventoryModelFetchDescendentsResponder::result(const LLSD& content) { LLSD category = *category_it; tcategory->fromLLSD(category); - - if (LLInventoryModelBackgroundFetch::instance().inventoryFetchStarted() || - LLInventoryModelBackgroundFetch::instance().libraryFetchStarted()) + + const BOOL recursive = getIsRecursive(tcategory->getUUID()); + + if (recursive) { - sFetchQueue.push_back(tcategory->getUUID()); + fetcher->mFetchQueue.push_back(LLInventoryModelBackgroundFetch::FetchQueueInfo(tcategory->getUUID(), recursive)); } else if ( !gInventory.isCategoryComplete(tcategory->getUUID()) ) { @@ -435,7 +436,7 @@ void LLInventoryModelFetchDescendentsResponder::result(const LLSD& content) gInventory.updateItem(titem); } - // set version and descendentcount according to message. + // Set version and descendentcount according to message. LLViewerInventoryCategory* cat = gInventory.getCategory(parent_id); if(cat) { @@ -455,32 +456,34 @@ void LLInventoryModelFetchDescendentsResponder::result(const LLSD& content) { LLSD folder_sd = *folder_it; - //These folders failed on the dataserver. We probably don't want to retry them. + // These folders failed on the dataserver. We probably don't want to retry them. llinfos << "Folder " << folder_sd["folder_id"].asString() << "Error: " << folder_sd["error"].asString() << llendl; } } - LLInventoryModelBackgroundFetch::instance().incrBulkFetch(-1); + fetcher->incrBulkFetch(-1); - if (LLInventoryModelBackgroundFetch::instance().isBulkFetchProcessingComplete()) + if (fetcher->isBulkFetchProcessingComplete()) { llinfos << "Inventory fetch completed" << llendl; - LLInventoryModelBackgroundFetch::instance().setAllFoldersFetched(); + fetcher->setAllFoldersFetched(); } gInventory.notifyObservers("fetchDescendents"); } -//If we get back an error (not found, etc...), handle it here +// If we get back an error (not found, etc...), handle it here. void LLInventoryModelFetchDescendentsResponder::error(U32 status, const std::string& reason) { + LLInventoryModelBackgroundFetch *fetcher = LLInventoryModelBackgroundFetch::getInstance(); + llinfos << "LLInventoryModelFetchDescendentsResponder::error " << status << ": " << reason << llendl; - LLInventoryModelBackgroundFetch::instance().incrBulkFetch(-1); + fetcher->incrBulkFetch(-1); - if (status==499) //timed out. Let's be awesome! + if (status==499) // timed out { for(LLSD::array_const_iterator folder_it = mRequestSD["folders"].beginArray(); folder_it != mRequestSD["folders"].endArray(); @@ -488,24 +491,31 @@ void LLInventoryModelFetchDescendentsResponder::error(U32 status, const std::str { LLSD folder_sd = *folder_it; LLUUID folder_id = folder_sd["folder_id"]; - sFetchQueue.push_front(folder_id); + const BOOL recursive = getIsRecursive(folder_id); + fetcher->mFetchQueue.push_front(LLInventoryModelBackgroundFetch::FetchQueueInfo(folder_id, recursive)); } } else { - if (LLInventoryModelBackgroundFetch::instance().isBulkFetchProcessingComplete()) + if (fetcher->isBulkFetchProcessingComplete()) { - LLInventoryModelBackgroundFetch::instance().setAllFoldersFetched(); + fetcher->setAllFoldersFetched(); } } gInventory.notifyObservers("fetchDescendents"); } -//static Bundle up a bunch of requests to send all at once. +BOOL LLInventoryModelFetchDescendentsResponder::getIsRecursive(const LLUUID& cat_id) const +{ + return (std::find(mRecursiveCatUUIDs.begin(),mRecursiveCatUUIDs.end(), cat_id) != mRecursiveCatUUIDs.end()); +} + +// Bundle up a bunch of requests to send all at once. +// static void LLInventoryModelBackgroundFetch::bulkFetch(std::string url) { //Background fetch is called from gIdleCallbacks in a loop until background fetch is stopped. - //If there are items in sFetchQueue, we want to check the time since the last bulkFetch was + //If there are items in mFetchQueue, we want to check the time since the last bulkFetch was //sent. If it exceeds our retry time, go ahead and fire off another batch. //Stopbackgroundfetch will be run from the Responder instead of here. @@ -520,7 +530,7 @@ void LLInventoryModelBackgroundFetch::bulkFetch(std::string url) (mBulkFetchCount > max_concurrent_fetches) || (mFetchTimer.getElapsedTimeF32() < mMinTimeBetweenFetches)) { - return; // just bail if we are disconnected. + return; // just bail if we are disconnected } U32 folder_count=0; @@ -528,11 +538,16 @@ void LLInventoryModelBackgroundFetch::bulkFetch(std::string url) U32 sort_order = gSavedSettings.getU32(LLInventoryPanel::DEFAULT_SORT_ORDER) & 0x1; + uuid_vec_t recursive_cats; + LLSD body; LLSD body_lib; - while (!(sFetchQueue.empty()) && (folder_count < max_batch_size)) + + while (!(mFetchQueue.empty()) && (folder_count < max_batch_size)) { - if (sFetchQueue.front().isNull()) //DEV-17797 + const FetchQueueInfo& fetch_info = mFetchQueue.front(); + const LLUUID &cat_id = fetch_info.mCatUUID; + if (cat_id.isNull()) //DEV-17797 { LLSD folder_sd; folder_sd["folder_id"] = LLUUID::null.asString(); @@ -545,7 +560,7 @@ void LLInventoryModelBackgroundFetch::bulkFetch(std::string url) } else { - LLViewerInventoryCategory* cat = gInventory.getCategory(sFetchQueue.front()); + const LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id); if (cat) { @@ -564,9 +579,9 @@ void LLInventoryModelBackgroundFetch::bulkFetch(std::string url) body["folders"].append(folder_sd); folder_count++; } - if (mInventoryFetchStarted || mLibraryFetchStarted) - { //Already have this folder but append child folders to list. - // add all children to queue + // May already have this folder, but append child folders to list. + if (fetch_info.mRecursive) + { LLInventoryModel::cat_array_t* categories; LLInventoryModel::item_array_t* items; gInventory.getDirectDescendentsOf(cat->getUUID(), categories, items); @@ -574,12 +589,15 @@ void LLInventoryModelBackgroundFetch::bulkFetch(std::string url) it != categories->end(); ++it) { - sFetchQueue.push_back((*it)->getUUID()); + mFetchQueue.push_back(FetchQueueInfo((*it)->getUUID(), fetch_info.mRecursive)); } } } } - sFetchQueue.pop_front(); + if (fetch_info.mRecursive) + recursive_cats.push_back(cat_id); + + mFetchQueue.pop_front(); } if (folder_count > 0) @@ -587,12 +605,15 @@ void LLInventoryModelBackgroundFetch::bulkFetch(std::string url) mBulkFetchCount++; if (body["folders"].size()) { - LLHTTPClient::post(url, body, new LLInventoryModelFetchDescendentsResponder(body),300.0); + LLInventoryModelFetchDescendentsResponder *fetcher = new LLInventoryModelFetchDescendentsResponder(body, recursive_cats); + LLHTTPClient::post(url, body, fetcher, 300.0); } if (body_lib["folders"].size()) { std::string url_lib = gAgent.getRegion()->getCapability("FetchLibDescendents"); - LLHTTPClient::post(url_lib, body_lib, new LLInventoryModelFetchDescendentsResponder(body_lib),300.0); + + LLInventoryModelFetchDescendentsResponder *fetcher = new LLInventoryModelFetchDescendentsResponder(body_lib, recursive_cats); + LLHTTPClient::post(url_lib, body_lib, fetcher, 300.0); } mFetchTimer.reset(); } @@ -601,3 +622,17 @@ void LLInventoryModelBackgroundFetch::bulkFetch(std::string url) setAllFoldersFetched(); } } + +bool LLInventoryModelBackgroundFetch::fetchQueueContainsNoDescendentsOf(const LLUUID& cat_id) const +{ + for (fetch_queue_t::const_iterator it = mFetchQueue.begin(); + it != mFetchQueue.end(); ++it) + { + const LLUUID& fetch_id = (*it).mCatUUID; + if (gInventory.isObjectDescendentOf(fetch_id, cat_id)) + return false; + } + return true; +} + + |