diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-06-26 15:19:36 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-06-28 12:47:35 +0200 |
commit | 47e04cf31c6165dd55dc20962ad9c72962b958bd (patch) | |
tree | c8c996c05d9fd8e2f611d5accc280678bcabd0de /sfx2 | |
parent | b399dba597c90777c0edf2c5b19d029b3bff23df (diff) |
tdf#125706 and tdf#125665 writer, speed up RDF
The RDF stuff is sloooooooow, so (a) add some caching and (b) fold a
very hot UNO_QUERY call.
To add the caching we need to add a new UNO interface, since
XEnumeration is not amenable to being cached.
Add an optimised getStatementsGraph_NoLock2 that skips the intermediate
enumeration object, and consequently a lot of locking/unlocking.
Cache by OUString key, to avoid expensive OUString<->OString conversion
when looking up entries in the cache.
For the test document in tdf#125706, this takes the time from 7s to 5s for me.
For the test document in tdf#125665, this takes the load time
from 60s to 7s for me.
Change-Id: I207387e975b4f107834edd0974134c481fb4012d
Reviewed-on: https://gerrit.libreoffice.org/74740
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/doc/DocumentMetadataAccess.cxx | 62 |
1 files changed, 18 insertions, 44 deletions
diff --git a/sfx2/source/doc/DocumentMetadataAccess.cxx b/sfx2/source/doc/DocumentMetadataAccess.cxx index 14c5d98ca5d2..83cd4ec3f6d4 100644 --- a/sfx2/source/doc/DocumentMetadataAccess.cxx +++ b/sfx2/source/doc/DocumentMetadataAccess.cxx @@ -36,6 +36,7 @@ #include <com/sun/star/rdf/Literal.hpp> #include <com/sun/star/rdf/URI.hpp> #include <com/sun/star/rdf/Repository.hpp> +#include <com/sun/star/rdf/XNamedGraph2.hpp> #include <rtl/ustrbuf.hxx> #include <rtl/uri.hxx> @@ -220,7 +221,7 @@ struct DocumentMetadataAccess_Impl const SfxObjectShell & m_rXmlIdRegistrySupplier; uno::Reference<rdf::XURI> m_xBaseURI; uno::Reference<rdf::XRepository> m_xRepository; - uno::Reference<rdf::XNamedGraph> m_xManifest; + uno::Reference<rdf::XNamedGraph2> m_xManifest; DocumentMetadataAccess_Impl( uno::Reference<uno::XComponentContext> const& i_xContext, SfxObjectShell const & i_rRegistrySupplier) @@ -228,7 +229,6 @@ struct DocumentMetadataAccess_Impl , m_rXmlIdRegistrySupplier(i_rRegistrySupplier) , m_xBaseURI() , m_xRepository() - , m_xManifest() { OSL_ENSURE(m_xContext.is(), "context null"); } @@ -394,26 +394,12 @@ removeFile(struct DocumentMetadataAccess_Impl const & i_rImpl, } } -static ::std::vector< uno::Reference< rdf::XURI > > +static css::uno::Sequence< uno::Reference< rdf::XURI > > getAllParts(struct DocumentMetadataAccess_Impl const & i_rImpl) { - ::std::vector< uno::Reference< rdf::XURI > > ret; try { - const uno::Reference<container::XEnumeration> xEnum( - i_rImpl.m_xManifest->getStatements( i_rImpl.m_xBaseURI.get(), - getURI<rdf::URIs::PKG_HASPART>(i_rImpl.m_xContext), nullptr), - uno::UNO_SET_THROW); - while (xEnum->hasMoreElements()) { - rdf::Statement stmt; - if (!(xEnum->nextElement() >>= stmt)) { - throw uno::RuntimeException(); - } - const uno::Reference<rdf::XURI> xPart(stmt.Object, - uno::UNO_QUERY); - if (!xPart.is()) continue; - ret.push_back(xPart); - } - return ret; + return i_rImpl.m_xManifest->getStatementsObjects( i_rImpl.m_xBaseURI.get(), + getURI<rdf::URIs::PKG_HASPART>(i_rImpl.m_xContext), nullptr); } catch (const uno::RuntimeException &) { throw; } catch (const uno::Exception &) { @@ -454,27 +440,14 @@ getAllParts(struct DocumentMetadataAccess_Impl const& i_rImpl, ::std::vector<uno::Reference<rdf::XURI>> ret; try { - const uno::Reference<container::XEnumeration> xEnum( - i_rImpl.m_xManifest->getStatements(i_rImpl.m_xBaseURI.get(), + css::uno::Sequence< uno::Reference< rdf::XURI > > parts1 + = i_rImpl.m_xManifest->getStatementsObjects(i_rImpl.m_xBaseURI.get(), getURI<rdf::URIs::PKG_HASPART>(i_rImpl.m_xContext), - nullptr), - uno::UNO_SET_THROW); - while (xEnum->hasMoreElements()) + nullptr); + for (auto const & xPart : parts1) { - rdf::Statement stmt; - if (!(xEnum->nextElement() >>= stmt)) - { - throw uno::RuntimeException(); - } - const uno::Reference<rdf::XURI> xPart(stmt.Object, uno::UNO_QUERY); - if (!xPart.is()) - continue; - - const uno::Reference<container::XEnumeration> xEnum2( - i_rImpl.m_xManifest->getStatements( - xPart.get(), getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext), i_xType.get()), - uno::UNO_SET_THROW); - if (xEnum2->hasMoreElements()) + if (i_rImpl.m_xManifest->hasStatements( + xPart.get(), getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext), i_xType.get())) ret.emplace_back(xPart); } return ret; @@ -773,10 +746,11 @@ retry: } // init manifest graph - const uno::Reference<rdf::XNamedGraph> xManifestGraph( - i_rImpl.m_xRepository->getGraph(xManifest)); - i_rImpl.m_xManifest.set(xManifestGraph.is() ? xManifestGraph : - i_rImpl.m_xRepository->createGraph(xManifest), uno::UNO_SET_THROW); + auto xManifestGraph = i_rImpl.m_xRepository->getGraph(xManifest); + if (xManifestGraph.is()) + i_rImpl.m_xManifest.set(xManifestGraph, uno::UNO_QUERY_THROW); + else + i_rImpl.m_xManifest.set(i_rImpl.m_xRepository->createGraph(xManifest), uno::UNO_QUERY_THROW); const uno::Reference<container::XEnumeration> xEnum( i_rImpl.m_xManifest->getStatements(nullptr, getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext), @@ -808,7 +782,7 @@ static void init(struct DocumentMetadataAccess_Impl & i_rImpl) i_rImpl.m_xManifest.set(i_rImpl.m_xRepository->createGraph( getURIForStream(i_rImpl, s_manifest)), - uno::UNO_SET_THROW); + uno::UNO_QUERY_THROW); // insert the document statement i_rImpl.m_xManifest->addStatement(i_rImpl.m_xBaseURI.get(), @@ -1134,7 +1108,7 @@ void SAL_CALL DocumentMetadataAccess::loadMetadataFromStorage( std::vector< OUString > MfstMetadataFiles; try { - const ::std::vector< uno::Reference< rdf::XURI > > parts( + const css::uno::Sequence< uno::Reference< rdf::XURI > > parts( getAllParts(*m_pImpl) ); const uno::Reference<rdf::XURI>& xContentFile( getURI<rdf::URIs::ODF_CONTENTFILE>(m_pImpl->m_xContext)); |