sw/source/core/doc/docnew.cxx |   27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

New commits:
commit 97a8db45e6ad8fb397edf5e239384637353f0b2f
Author:     Michael Stahl <[email protected]>
AuthorDate: Wed Jun 1 20:30:50 2022 +0200
Commit:     Thorsten Behrens <[email protected]>
CommitDate: Tue Jun 21 23:39:46 2022 +0200

    tdf#148309 sw_redlinehide: fix mail merge performance regression
    
    The problem is that in the call to pTargetShell->EndAllAction(), the
    cursor is on the node before the newly appended one that has the page
    break, and only this node is formatted (via GetFormatted()), so no new
    page frames are inserted in the layout, which then creates massive
    performance problems later, particularly since the bugdoc contains
    multiple at-page anchored flys.
    
    (regression from commit 42448f48bb48a13d6618a181b12840db6d85c574)
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135356
    Tested-by: Michael Stahl <[email protected]>
    Reviewed-by: Michael Stahl <[email protected]>
    (cherry picked from commit ff525d0d70ea9d189a430bde944b56d048b03e55)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135273
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <[email protected]>
    (cherry picked from commit 57cd4735a7312174e63d2a1a3dd3831443169530)
    
    Revert "trac#34262 Revert "tdf#144565 sw_redlinehide: fix mailmerge when 
flys anchored at last node""
    
    This reverts commit 228537cebb6ffa75e7e2270fb7bfd6e91fa6ba2c.
    The performance regression should be fixed with above commit.
    
    Change-Id: I05cd2a515a7f67132ab1c8c6fa0d675252ea3a15
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136181
    Reviewed-by: Thorsten Behrens <[email protected]>
    Tested-by: Thorsten Behrens <[email protected]>

diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 984f2335bc45..6b041fa96c51 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -1054,19 +1054,19 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, 
sal_uInt16 const nStartPageNu
         {
             SwNodeIndex aBreakIdx( GetNodes().GetEndOfContent(), -1 );
             SwPosition aBreakPos( aBreakIdx );
-            // InsertPageBreak just works on SwTextNode nodes, so make
-            // sure the last node is one!
-            bool bIsTextNode = aBreakIdx.GetNode().IsTextNode();
-            if ( !bIsTextNode )
-                getIDocumentContentOperations().AppendTextNode( aBreakPos );
-            const OUString name = pTargetPageDesc->GetName();
-            pTargetShell->InsertPageBreak( &name, nStartPageNumber );
-            if ( !bIsTextNode )
-            {
-                pTargetShell->SttEndDoc( false );
-                --aBreakIdx;
-                GetNodes().Delete( aBreakIdx );
-            }
+            // insert new node - will be removed at the end...
+            // (don't SplitNode() as it may move flys to the wrong node)
+            getIDocumentContentOperations().AppendTextNode(aBreakPos);
+            SwFormatPageDesc pageDesc(pTargetPageDesc);
+            pageDesc.SetNumOffset(nStartPageNumber);
+            // set break on the last paragraph
+            getIDocumentContentOperations().InsertPoolItem(SwPaM(aBreakPos),
+                    pageDesc, SetAttrMode::DEFAULT, pTargetShell->GetLayout());
+            // tdf#148309 move to the last node - so that the "flush page 
break"
+            // code below will format the frame of the node with the page 
break,
+            // which is required for new page frames to be created!  Else 
layout
+            // performance will be terrible.
+            pTargetShell->SttEndDoc(false);
 
             // There is now a new empty text node on the new page. If it has
             // any marks, those are from the previous page: move them back
@@ -1097,6 +1097,7 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, 
sal_uInt16 const nStartPageNu
             if ( !bDeletePrevious )
             {
                 SAL_INFO( "sw.pageframe", "(Flush pagebreak AKA EndAllAction" 
);
+                
assert(pTargetShell->GetCursor()->GetPoint()->nNode.GetNode().GetTextNode()->GetSwAttrSet().HasItem(RES_PAGEDESC));
                 pTargetShell->EndAllAction();
                 SAL_INFO( "sw.pageframe",  "Flush changes AKA EndAllAction)" );
                 pTargetShell->StartAllAction();

Reply via email to