diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index a1191e8a31..a5dca715cb 100644 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -1044,6 +1044,13 @@ void AISAPI::InvokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t ht U32 AISUpdate::sBatchFrameCount = 0; LLTimer AISUpdate::sBatchTimer; +// Coalesces the deferred gInventory::notifyObservers() calls issued below +// when the change backlog exceeds MAX_UPDATE_BACKLOG, so repeated iterations +// while the backlog remains large don't flood gMainloopWork with duplicate +// postToMainCoro callbacks. Cleared once the posted callback actually runs +// notifyObservers(). +static bool sAISNotifyObserversPending = false; + AISUpdate::AISUpdate(const LLSD& update, AISAPI::COMMAND_TYPE type, const LLSD& request_body) : mType(type) { @@ -1683,7 +1690,16 @@ void AISUpdate::doUpdate() // fetching can receive massive amount of items and folders if (gInventory.getChangedIDs().size() > MAX_UPDATE_BACKLOG) { - gInventory.notifyObservers(); + if (!sAISNotifyObserversPending) + { + sAISNotifyObserversPending = true; + LLAppViewer::instance()->postToMainCoro( + []() + { + gInventory.notifyObservers(); + sAISNotifyObserversPending = false; + }); + } checkTimeout(); } } @@ -1744,7 +1760,16 @@ void AISUpdate::doUpdate() // fetching can receive massive amount of items and folders if (gInventory.getChangedIDs().size() > MAX_UPDATE_BACKLOG) { - gInventory.notifyObservers(); + if (!sAISNotifyObserversPending) + { + sAISNotifyObserversPending = true; + LLAppViewer::instance()->postToMainCoro( + []() + { + gInventory.notifyObservers(); + sAISNotifyObserversPending = false; + }); + } checkTimeout(); } } @@ -1815,6 +1840,9 @@ void AISUpdate::doUpdate() checkTimeout(); - gInventory.notifyObservers(); + LLAppViewer::instance()->postToMainCoro( + []() + { + gInventory.notifyObservers(); + }); } -