From 65d026f39cff52c96be95871e16a3d6714203d2e Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Tue, 20 May 2014 10:19:25 -0400 Subject: cp#1000072: Purge one document shell at a time, to avoid freeze. Import especially when we have a whole bunch of large-ish documents open in the background. Change-Id: I614e6daab3481c09dae47c8407497d77aec40480 --- sc/source/core/data/documen8.cxx | 2 +- sc/source/ui/docshell/externalrefmgr.cxx | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx index 4563b02364c3..6b2f02822480 100644 --- a/sc/source/core/data/documen8.cxx +++ b/sc/source/core/data/documen8.cxx @@ -806,7 +806,7 @@ void ScDocument::UpdateExternalRefLinks(Window* pWin) ScProgress aProgress(GetDocumentShell(), "Updating external links", aRefLinks.size()); for (size_t i = 0, n = aRefLinks.size(); i < n; ++i) { - aProgress.SetState(i); + aProgress.SetState(i+1); ScExternalRefLink* pRefLink = aRefLinks[i]; if (pRefLink->Update()) diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx index ded749f222d4..525bbce04c4a 100644 --- a/sc/source/ui/docshell/externalrefmgr.cxx +++ b/sc/source/ui/docshell/externalrefmgr.cxx @@ -2796,19 +2796,20 @@ void ScExternalRefManager::notifyAllLinkListeners(sal_uInt16 nFileId, LinkUpdate void ScExternalRefManager::purgeStaleSrcDocument(sal_Int32 nTimeOut) { - DocShellMap aNewDocShells; + // To avoid potentially freezing Calc, we close one stale document at a time. DocShellMap::iterator itr = maDocShells.begin(), itrEnd = maDocShells.end(); for (; itr != itrEnd; ++itr) { // in 100th of a second. sal_Int32 nSinceLastAccess = (Time( Time::SYSTEM ) - itr->second.maLastAccess).GetTime(); - if (nSinceLastAccess < nTimeOut) - aNewDocShells.insert(*itr); - else - // Timed out. Let's close this. + if (nSinceLastAccess >= nTimeOut) + { + // Timed out. Let's close this, and exit the loop. itr->second.maShell->DoClose(); + maDocShells.erase(itr); + break; + } } - maDocShells.swap(aNewDocShells); if (maDocShells.empty()) maSrcDocTimer.Stop(); -- cgit