This commit is contained in:
Siana Gearz
2013-05-13 02:43:49 +02:00
12 changed files with 174 additions and 142 deletions

View File

@@ -204,7 +204,8 @@ void LLInventoryModelBackgroundFetch::backgroundFetch()
std::string url = region->getCapability("FetchInventory2");
if (!url.empty())
{
if (!mPerServicePtr)
bool mPerServicePtr_initialized = !!mPerServicePtr;
if (!mPerServicePtr_initialized)
{
// One time initialization needed for bulkFetch().
std::string servicename = AIPerService::extract_canonical_servicename(url);
@@ -212,10 +213,14 @@ void LLInventoryModelBackgroundFetch::backgroundFetch()
{
llinfos << "Initialized service name for bulk inventory fetching with \"" << servicename << "\"." << llendl;
mPerServicePtr = AIPerService::instance(servicename);
mPerServicePtr_initialized = true;
}
}
bulkFetch();
return;
if (mPerServicePtr_initialized)
{
bulkFetch();
return;
}
}
}
@@ -600,30 +605,29 @@ void LLInventoryModelBackgroundFetch::bulkFetch()
LLViewerRegion* region = gAgent.getRegion();
if (gDisconnected || !region) return;
if (!AIPerService::wantsMoreHTTPRequestsFor(mPerServicePtr))
{
return; // Wait.
}
// If AIPerService::wantsMoreHTTPRequestsFor returns true, then it approved ONE request.
// The code below might fire off zero, one or even more than one requests however!
// This object keeps track of that.
AIPerService::Approvement approvement(mPerServicePtr);
U32 item_count=0;
U32 folder_count=0;
U32 max_batch_size=5;
U32 const max_batch_size = 5;
U32 sort_order = gSavedSettings.getU32(LLInventoryPanel::DEFAULT_SORT_ORDER) & 0x1;
uuid_vec_t recursive_cats;
U32 folder_count=0;
U32 folder_lib_count=0;
U32 item_count=0;
U32 item_lib_count=0;
// This function can do up to four requests at once.
LLPointer<AIPerService::Approvement> approved_folder;
LLPointer<AIPerService::Approvement> approved_folder_lib;
LLPointer<AIPerService::Approvement> approved_item;
LLPointer<AIPerService::Approvement> approved_item_lib;
LLSD folder_request_body;
LLSD folder_request_body_lib;
LLSD item_request_body;
LLSD item_request_body_lib;
while (!mFetchQueue.empty()
&& (item_count + folder_count) < max_batch_size)
while (!mFetchQueue.empty())
{
const FetchQueueInfo& fetch_info = mFetchQueue.front();
if (fetch_info.mIsCategory)
@@ -645,10 +649,27 @@ void LLInventoryModelBackgroundFetch::bulkFetch()
folder_sd["fetch_items"] = (LLSD::Boolean)TRUE;
if (ALEXANDRIA_LINDEN_ID == cat->getOwnerID())
{
if (folder_lib_count == max_batch_size ||
(folder_lib_count == 0 &&
!(approved_folder_lib = AIPerService::approveHTTPRequestFor(mPerServicePtr))))
{
break;
}
folder_request_body_lib["folders"].append(folder_sd);
++folder_lib_count;
}
else
{
if (folder_count == max_batch_size ||
(folder_count == 0 &&
!(approved_folder = AIPerService::approveHTTPRequestFor(mPerServicePtr))))
{
break;
}
folder_request_body["folders"].append(folder_sd);
folder_count++;
++folder_count;
}
}
// May already have this folder, but append child folders to list.
if (fetch_info.mRecursive)
@@ -678,77 +699,69 @@ void LLInventoryModelBackgroundFetch::bulkFetch()
item_sd["item_id"] = itemp->getUUID();
if (itemp->getPermissions().getOwner() == gAgent.getID())
{
if (item_count == max_batch_size ||
(item_count == 0 &&
!(approved_item = AIPerService::approveHTTPRequestFor(mPerServicePtr))))
{
break;
}
item_request_body.append(item_sd);
++item_count;
}
else
{
if (item_lib_count == max_batch_size ||
(item_lib_count == 0 &&
!(approved_item_lib = AIPerService::approveHTTPRequestFor(mPerServicePtr))))
{
break;
}
item_request_body_lib.append(item_sd);
++item_lib_count;
}
//itemp->fetchFromServer();
item_count++;
}
}
mFetchQueue.pop_front();
}
if (item_count + folder_count > 0)
if (item_count + folder_count + item_lib_count + folder_lib_count > 0)
{
if (folder_count)
{
std::string url = region->getCapability("FetchInventoryDescendents2");
mFetchCount++;
if (folder_request_body["folders"].size())
{
LLInventoryModelFetchDescendentsResponder *fetcher = new LLInventoryModelFetchDescendentsResponder(folder_request_body, recursive_cats);
LLHTTPClient::post_nb(url, folder_request_body, fetcher);
approvement.honored();
}
if (folder_request_body_lib["folders"].size())
{
std::string url_lib = gAgent.getRegion()->getCapability("FetchLibDescendents2");
LLInventoryModelFetchDescendentsResponder *fetcher = new LLInventoryModelFetchDescendentsResponder(folder_request_body_lib, recursive_cats);
LLHTTPClient::post_nb(url_lib, folder_request_body_lib, fetcher);
approvement.honored();
}
llassert(!url.empty());
++mFetchCount;
LLInventoryModelFetchDescendentsResponder *fetcher = new LLInventoryModelFetchDescendentsResponder(folder_request_body, recursive_cats);
LLHTTPClient::post_approved(url, folder_request_body, fetcher, approved_folder);
}
if (folder_lib_count)
{
std::string url = gAgent.getRegion()->getCapability("FetchLibDescendents2");
llassert(!url.empty());
++mFetchCount;
LLInventoryModelFetchDescendentsResponder *fetcher = new LLInventoryModelFetchDescendentsResponder(folder_request_body_lib, recursive_cats);
LLHTTPClient::post_approved(url, folder_request_body_lib, fetcher, approved_folder_lib);
}
if (item_count)
{
std::string url;
if (item_request_body.size())
{
mFetchCount++;
url = region->getCapability("FetchInventory2");
llassert(!url.empty());
if (!url.empty())
{
LLSD body;
body["agent_id"] = gAgent.getID();
body["items"] = item_request_body;
LLHTTPClient::post_nb(url, body, new LLInventoryModelFetchItemResponder(body));
approvement.honored();
}
}
if (item_request_body_lib.size())
{
mFetchCount++;
url = region->getCapability("FetchLib2");
llassert(!url.empty());
if (!url.empty())
{
LLSD body;
body["agent_id"] = gAgent.getID();
body["items"] = item_request_body_lib;
LLHTTPClient::post_nb(url, body, new LLInventoryModelFetchItemResponder(body));
approvement.honored();
}
}
std::string url = region->getCapability("FetchInventory2");
llassert(!url.empty());
++mFetchCount;
LLSD body;
body["agent_id"] = gAgent.getID();
body["items"] = item_request_body;
LLHTTPClient::post_approved(url, body, new LLInventoryModelFetchItemResponder(body), approved_item);
}
if (item_lib_count)
{
std::string url = region->getCapability("FetchLib2");
llassert(!url.empty());
++mFetchCount;
LLSD body;
body["agent_id"] = gAgent.getID();
body["items"] = item_request_body_lib;
LLHTTPClient::post_approved(url, body, new LLInventoryModelFetchItemResponder(body), approved_item_lib);
}
mFetchTimer.reset();
}

View File

@@ -1272,13 +1272,14 @@ bool LLTextureFetchWorker::doWork(S32 param)
}
// Let AICurl decide if we can process more HTTP requests at the moment or not.
if (!AIPerService::wantsMoreHTTPRequestsFor(mPerServicePtr))
// AIPerService::approveHTTPRequestFor returns approvement for ONE request.
// This object keeps track of whether or not that is honored.
LLPointer<AIPerService::Approvement> approved = AIPerService::approveHTTPRequestFor(mPerServicePtr);
if (!approved)
{
return false ; //wait.
}
// If AIPerService::wantsMoreHTTPRequestsFor returns true then it approved ONE request.
// This object keeps track of whether or not that is honored.
AIPerService::Approvement approvement(mPerServicePtr);
mFetcher->removeFromNetworkQueue(this, false);
@@ -1324,9 +1325,7 @@ bool LLTextureFetchWorker::doWork(S32 param)
}
LLHTTPClient::request(mUrl, LLHTTPClient::HTTP_GET, NULL,
new HTTPGetResponder(mFetcher, mID, LLTimer::getTotalTime(), mRequestedSize, mRequestedOffset, true),
headers/*,*/ DEBUG_CURLIO_PARAM(debug_off), keep_alive, no_does_authentication, allow_compressed_reply, NULL, 0, NULL, false);
// Now the request was added to the command queue.
approvement.honored();
headers, approved/*,*/ DEBUG_CURLIO_PARAM(debug_off), keep_alive, no_does_authentication, allow_compressed_reply, NULL, 0, NULL);
res = true;
}
if (!res)