sw/qa/extras/odfexport/data/tdf160877.odt |binary
 sw/qa/extras/odfexport/odfexport2.cxx     |   14 ++++++++
 sw/source/core/edit/edfcol.cxx            |   52 +++++++++++++++++-------------
 3 files changed, 45 insertions(+), 21 deletions(-)

New commits:
commit e83f7dd8bcb40105d933f72b80eb337f716b94e8
Author:     Noel Grandin <[email protected]>
AuthorDate: Fri Jun 14 09:38:52 2024 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Wed Jun 19 11:45:05 2024 +0200

    tdf#144208 speedup doc with lots of redline (10)
    
    don't call SwRDFHelper::getStatements for every single paragraph, we can
    call this once and re-use the result
    
    Change-Id: I0277ecbb113b8333839172bddd7978f4b3a7259a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168850
    Tested-by: Xisco Fauli <[email protected]>
    Reviewed-by: Xisco Fauli <[email protected]>
    Reviewed-by: Noel Grandin <[email protected]>
    (cherry picked from commit 0e33dff4252f3124c7ecc591befa56f0fb0e1895)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168809
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168865

diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index 29ea37b52d3d..076f1fc3f7d0 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -617,7 +617,7 @@ bool lcl_UpdateParagraphClassificationField(SwDoc* pDoc,
     return lcl_DoUpdateParagraphSignatureField(*pDoc, xField, sDisplayText);
 }
 
-void lcl_ValidateParagraphSignatures(SwDoc& rDoc, const 
uno::Reference<text::XTextContent>& xParagraph, const bool updateDontRemove)
+void lcl_ValidateParagraphSignatures(SwDoc& rDoc, const 
uno::Reference<text::XTextContent>& xParagraph, const bool updateDontRemove, 
const uno::Sequence<uno::Reference<css::rdf::XURI>>& rGraphNames)
 {
     SwDocShell* pDocShell = rDoc.GetDocShell();
     if (!pDocShell)
@@ -628,8 +628,10 @@ void lcl_ValidateParagraphSignatures(SwDoc& rDoc, const 
uno::Reference<text::XTe
     // Check if the paragraph is signed.
     try
     {
-        const std::pair<OUString, OUString> pair = lcl_getRDF(xModel, 
xParagraph, ParagraphSignatureLastIdRDFName);
-        if (pair.second.isEmpty())
+        const css::uno::Reference<css::rdf::XResource> xSubject(xParagraph, 
uno::UNO_QUERY);
+        std::map<OUString, OUString> aStatements = 
SwRDFHelper::getStatements(xModel, rGraphNames, xSubject);
+        const auto it = aStatements.find(ParagraphSignatureLastIdRDFName);
+        if (it == aStatements.end() || it->second.isEmpty())
             return;
     }
     catch (const ::css::uno::Exception&)
@@ -1847,8 +1849,13 @@ void 
SwEditShell::ValidateParagraphSignatures(SwTextNode* pNode, bool updateDont
             SetParagraphSignatureValidation(bOldValidationFlag);
         });
 
+    SwDocShell* pDocShell = GetDoc()->GetDocShell();
+    if (!pDocShell)
+        return;
+
+    uno::Sequence<uno::Reference<css::rdf::XURI>> aGraphNames = 
SwRDFHelper::getGraphNames(pDocShell->GetBaseModel(), MetaNS);
     rtl::Reference<SwXParagraph> xParentText = 
SwXParagraph::CreateXParagraph(*GetDoc(), pNode, nullptr);
-    lcl_ValidateParagraphSignatures(*GetDoc(), xParentText, updateDontRemove);
+    lcl_ValidateParagraphSignatures(*GetDoc(), xParentText, updateDontRemove, 
aGraphNames);
 }
 
 void SwEditShell::ValidateCurrentParagraphSignatures(bool updateDontRemove)
@@ -1884,10 +1891,11 @@ void SwEditShell::ValidateAllParagraphSignatures(bool 
updateDontRemove)
     uno::Reference<container::XEnumeration> xParagraphs = 
xParagraphEnumerationAccess->createEnumeration();
     if (!xParagraphs.is())
         return;
+    uno::Sequence<uno::Reference<css::rdf::XURI>> aGraphNames = 
SwRDFHelper::getGraphNames(pDocShell->GetBaseModel(), MetaNS);
     while (xParagraphs->hasMoreElements())
     {
         uno::Reference<text::XTextContent> 
xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY);
-        lcl_ValidateParagraphSignatures(*GetDoc(), xParagraph, 
updateDontRemove);
+        lcl_ValidateParagraphSignatures(*GetDoc(), xParagraph, 
updateDontRemove, aGraphNames);
     }
 }
 
@@ -1939,7 +1947,7 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
 
     static constexpr OUString sBlank(u""_ustr);
     const sfx::ClassificationKeyCreator 
aKeyCreator(SfxClassificationHelper::getPolicyType());
-
+    uno::Sequence<uno::Reference<css::rdf::XURI>> aGraphNames = 
SwRDFHelper::getGraphNames(xModel, MetaNS);
     while (xParagraphs->hasMoreElements())
     {
         uno::Reference<text::XTextContent> 
xParaOrTable(xParagraphs->nextElement(), uno::UNO_QUERY);
@@ -1948,7 +1956,9 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
         try
         {
             const css::uno::Reference<css::rdf::XResource> 
xSubject(xParagraph);
-            const OUString sFieldNames = lcl_getRDF(xModel, xSubject, 
ParagraphClassificationFieldNamesRDFName).second;
+            std::map<OUString, OUString> aParagraphStatements = 
SwRDFHelper::getStatements(xModel, aGraphNames, xSubject);
+            auto it = 
aParagraphStatements.find(ParagraphClassificationFieldNamesRDFName);
+            const OUString sFieldNames = (it != aParagraphStatements.end()) ? 
it->second : OUString();
 
             std::vector<svx::ClassificationResult> aResults;
             if (!sFieldNames.isEmpty())
@@ -1961,9 +1971,14 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
                     if (sCurFieldName.isEmpty())
                         break;
 
-                    const std::pair<OUString, OUString> fieldNameValue = 
lcl_getRDF(xModel, xSubject, sCurFieldName);
-                    const OUString sName = fieldNameValue.first;
-                    const OUString sValue = fieldNameValue.second;
+                    OUString sName;
+                    OUString sValue;
+                    it = aParagraphStatements.find(sCurFieldName);
+                    if (it != aParagraphStatements.end())
+                    {
+                        sName = it->first;
+                        sValue = it->second;
+                    }
 
                     if (aKeyCreator.isMarkingTextKey(sName))
                     {
@@ -1998,7 +2013,7 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
 
             // Get Signatures
             std::map<OUString, SignatureDescr> aSignatures;
-            for (const auto& pair : lcl_getRDFStatements(xModel, 
uno::Reference<css::text::XTextContent>(xParagraph)))
+            for (const auto& pair : aParagraphStatements)
             {
                 const OUString& sName = pair.first;
                 if (sName.startsWith(ParagraphSignatureRDFNamespace))
@@ -2039,7 +2054,7 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
                 }
             }
 
-            lcl_ValidateParagraphSignatures(*GetDoc(), xParagraph, true); // 
Validate and Update signatures.
+            lcl_ValidateParagraphSignatures(*GetDoc(), xParagraph, true, 
aGraphNames); // Validate and Update signatures.
         }
         catch (const std::exception&)
         {
commit ce0e3f5ac90e580c21326993573bcc13fdebaae7
Author:     Xisco Fauli <[email protected]>
AuthorDate: Wed Jun 5 13:55:08 2024 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Wed Jun 19 11:44:57 2024 +0200

    tdf#160877: call lcl_getRDF since graph-names can change
    
    partially revert 3750d0533e0e00941e5aef92fe5a26b6e7e27734
    "sw: paragraph-sign: get graph-names only once"
    
    Change-Id: I7f99679f4a361acdd841037b782421a53350dbbb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168477
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <[email protected]>
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168671
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/sw/qa/extras/odfexport/data/tdf160877.odt 
b/sw/qa/extras/odfexport/data/tdf160877.odt
new file mode 100644
index 000000000000..7137eee8067a
Binary files /dev/null and b/sw/qa/extras/odfexport/data/tdf160877.odt differ
diff --git a/sw/qa/extras/odfexport/odfexport2.cxx 
b/sw/qa/extras/odfexport/odfexport2.cxx
index fb45d5c8e93c..a2acec11393f 100644
--- a/sw/qa/extras/odfexport/odfexport2.cxx
+++ b/sw/qa/extras/odfexport/odfexport2.cxx
@@ -1373,6 +1373,20 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf160700)
     assertXPath(pXmlDoc, 
"//office:text/text:list/text:list-item/text:p/text:bookmark"_ostr);
 }
 
+DECLARE_ODFEXPORT_TEST(testTdf160877, "tdf160877.odt")
+{
+    CPPUNIT_ASSERT_EQUAL(1, getPages());
+
+    uno::Reference<text::XText> xHeaderTextPage1 = 
getProperty<uno::Reference<text::XText>>(
+        getStyles("PageStyles")->getByName("Standard"), "HeaderTextFirst");
+    CPPUNIT_ASSERT_EQUAL(OUString("Classification: General Business"), 
xHeaderTextPage1->getString());
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: (Sign GB)Test
+    // - Actual  : Test
+    CPPUNIT_ASSERT_EQUAL(OUString("(Sign GB)Test"), 
getParagraph(1)->getString());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index f02273e07318..29ea37b52d3d 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -1939,7 +1939,6 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
 
     static constexpr OUString sBlank(u""_ustr);
     const sfx::ClassificationKeyCreator 
aKeyCreator(SfxClassificationHelper::getPolicyType());
-    const css::uno::Sequence<css::uno::Reference<rdf::XURI>> aGraphNames = 
SwRDFHelper::getGraphNames(xModel, MetaNS);
 
     while (xParagraphs->hasMoreElements())
     {
@@ -1949,14 +1948,11 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
         try
         {
             const css::uno::Reference<css::rdf::XResource> 
xSubject(xParagraph);
-            const std::map<OUString, OUString> aStatements = 
SwRDFHelper::getStatements(xModel, aGraphNames, xSubject);
+            const OUString sFieldNames = lcl_getRDF(xModel, xSubject, 
ParagraphClassificationFieldNamesRDFName).second;
 
-            const auto it = 
aStatements.find(ParagraphClassificationFieldNamesRDFName);
-            const OUString sFieldNames = (it != aStatements.end() ? it->second 
: sBlank);
             std::vector<svx::ClassificationResult> aResults;
             if (!sFieldNames.isEmpty())
             {
-                assert(it != aStatements.end() && "can only be non-empty if it 
was valid");
                 // Order the fields
                 sal_Int32 nIndex = 0;
                 do
@@ -1965,10 +1961,9 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
                     if (sCurFieldName.isEmpty())
                         break;
 
-                    const auto it2 = aStatements.find(sCurFieldName);
-                    bool bStatementFound = it2 != aStatements.end();
-                    const OUString sName = bStatementFound ? it->first : 
sBlank;
-                    const OUString sValue = bStatementFound ? it->second : 
sBlank;
+                    const std::pair<OUString, OUString> fieldNameValue = 
lcl_getRDF(xModel, xSubject, sCurFieldName);
+                    const OUString sName = fieldNameValue.first;
+                    const OUString sValue = fieldNameValue.second;
 
                     if (aKeyCreator.isMarkingTextKey(sName))
                     {
@@ -1976,14 +1971,14 @@ void 
SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures()
                     }
                     else if (aKeyCreator.isCategoryNameKey(sName))
                     {
-                        const auto it3 = 
aStatements.find(ParagraphClassificationAbbrRDFName);
-                        const OUString sAbbreviatedName = (it3 != 
aStatements.end() && !it3->second.isEmpty() ? it3->second : sValue);
+                        const std::pair<OUString, OUString> pairAbbr = 
lcl_getRDF(xModel, xSubject, ParagraphClassificationAbbrRDFName);
+                        const OUString sAbbreviatedName = 
(!pairAbbr.second.isEmpty() ? pairAbbr.second : sValue);
                         aResults.push_back({ 
svx::ClassificationType::CATEGORY, sValue, sAbbreviatedName, sBlank });
                     }
                     else if (aKeyCreator.isCategoryIdentifierKey(sName))
                     {
-                        const auto it3 = 
aStatements.find(ParagraphClassificationAbbrRDFName);
-                        const OUString sAbbreviatedName = (it3 != 
aStatements.end() && !it3->second.isEmpty() ? it3->second : sValue);
+                        const std::pair<OUString, OUString> pairAbbr = 
lcl_getRDF(xModel, xSubject, ParagraphClassificationAbbrRDFName);
+                        const OUString sAbbreviatedName = 
(!pairAbbr.second.isEmpty() ? pairAbbr.second : sValue);
                         aResults.push_back({ 
svx::ClassificationType::CATEGORY, sBlank, sAbbreviatedName, sValue });
                     }
                     else if (aKeyCreator.isMarkingKey(sName))

Reply via email to