Kaydet (Commit) 8d115315 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski Kaydeden (comit) Michael Stahl

Copy mail merge source instead of loading

Currently a mail merge loads the styles from the source document
and also loads the original source per mail merge dataset.

The new code is based on the MergeDocuments function and swaps the
loading with an internal document copy to improve mail merge
throughtput.

For a mail merge with 99 datasets and a two pages document,
callgrind shows an improvement from routhly 44 to 31 billion
inclusive instructions for the single SwXMailMerge::execute call.

Change-Id: I6929ba371f81c3ea1f26ea3a25e7751bc53256e3
Reviewed-on: https://gerrit.libreoffice.org/7433Tested-by: 's avatarMichael Stahl <mstahl@redhat.com>
Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst e1f90846
...@@ -869,11 +869,8 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell, ...@@ -869,11 +869,8 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
pSfxDispatcher->Execute( pSourceDocSh->HasName() ? SID_SAVEDOC : SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD); pSfxDispatcher->Execute( pSourceDocSh->HasName() ? SID_SAVEDOC : SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD);
if( !pSourceDocSh->IsModified() ) if( !pSourceDocSh->IsModified() )
{ {
SfxMedium* pOrig = pSourceDocSh->GetMedium(); const SfxFilter* pStoreToFilter = SwIoSystem::GetFileFilter(
OUString sSourceDocumentURL(pOrig->GetURLObject().GetMainURL( INetURLObject::NO_DECODE )); pSourceDocSh->GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), ::aEmptyOUStr );
const SfxFilter* pSfxFlt = SwIoSystem::GetFileFilter(
sSourceDocumentURL, ::aEmptyOUStr );
const SfxFilter* pStoreToFilter = pSfxFlt;
SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer(); SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
const OUString* pStoreToFilterOptions = 0; const OUString* pStoreToFilterOptions = 0;
...@@ -922,14 +919,7 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell, ...@@ -922,14 +919,7 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() ); pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() );
pTargetShell = pTargetView->GetWrtShellPtr(); pTargetShell = pTargetView->GetWrtShellPtr();
//copy the styles from the source to the target document //copy the styles from the source to the target document
SwgReaderOption aOpt; pTargetView->GetDocShell()->_LoadStyles( *pSourceDocSh, sal_True );
aOpt.SetTxtFmts( sal_True );
aOpt.SetFrmFmts( sal_True );
aOpt.SetPageDescs( sal_True );
aOpt.SetNumRules( sal_True );
aOpt.SetMerge( sal_False );
pTargetView->GetDocShell()->LoadStylesFromFile(
sSourceDocumentURL, aOpt, sal_True );
//determine the page style and number used at the start of the source document //determine the page style and number used at the start of the source document
pSourceShell->SttEndDoc(sal_True); pSourceShell->SttEndDoc(sal_True);
nStartingPageNo = pSourceShell->GetVirtPageNum(); nStartingPageNo = pSourceShell->GetVirtPageNum();
...@@ -1026,13 +1016,19 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell, ...@@ -1026,13 +1016,19 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
for (sal_uInt16 i = 0; i < 25; i++) for (sal_uInt16 i = 0; i < 25; i++)
Application::Reschedule(); Application::Reschedule();
// Create and save new document
// The SfxObjectShell will be closed explicitly later but it is more safe to use SfxObjectShellLock here // The SfxObjectShell will be closed explicitly later but it is more safe to use SfxObjectShellLock here
SfxObjectShellLock xWorkDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL )); SfxObjectShellLock xWorkDocSh;
SfxMedium* pWorkMed = new SfxMedium( sSourceDocumentURL, STREAM_STD_READ ); // copy the source document
pWorkMed->SetFilter( pSfxFlt ); if( 1 == nDocNo && (bAsSingleFile || rMergeDescriptor.bCreateSingleFile) )
{
uno::Reference< util::XCloneable > xClone( pSourceDocSh->GetModel(), uno::UNO_QUERY);
uno::Reference< lang::XUnoTunnel > xWorkDocShell( xClone->createClone(), uno::UNO_QUERY);
SwXTextDocument* pWorkModel = reinterpret_cast<SwXTextDocument*>(xWorkDocShell->getSomething(SwXTextDocument::getUnoTunnelId()));
xWorkDocSh = pWorkModel->GetDocShell();
}
else
xWorkDocSh = pSourceDocSh->GetDoc()->CreateCopy( true );
if (xWorkDocSh->DoLoad(pWorkMed))
{ {
//create a view frame for the document //create a view frame for the document
SfxViewFrame* pWorkFrame = SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 ); SfxViewFrame* pWorkFrame = SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment