From b8339a06050fcbff25e3c990e1ff8ca02dc7bad5 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Tue, 10 Dec 2013 15:56:06 -0500 Subject: [PATCH 058/109] fdo#66969: Reset group dimension data from all referencing pivot objects. The previous code was doing it only with the first referencing pivot table, which would break the rest of them sharing the same cache if the first one doesn't contain all group dimensions used in all of the referencing pivot tables. Change-Id: I35d6907ef8db7ed69db42583cac92b2b74406e2c (cherry picked from commit b3977983e9f662392426f581516d86d7034ad0fd) Reviewed-on: https://gerrit.libreoffice.org/7028 Reviewed-by: Eike Rathke Tested-by: Eike Rathke --- sc/inc/dpobject.hxx | 10 +++---- sc/source/core/data/dpobject.cxx | 57 ++++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx index 06d4957..51d4790 100644 --- a/sc/inc/dpobject.hxx +++ b/sc/inc/dpobject.hxx @@ -290,7 +290,7 @@ public: private: ScDPCache* getExistingCache(const ScRange& rRange); - void updateCache(const ScRange& rRange, const ScDPDimensionSaveData* pDimData, std::set& rRefs); + void updateCache(const ScRange& rRange, std::set& rRefs); bool remove(const ScDPCache* p); }; @@ -313,8 +313,7 @@ public: ScDPCache* getExistingCache(const OUString& rName); void updateCache( - const OUString& rName, const ScRange& rRange, - const ScDPDimensionSaveData* pDimData, std::set& rRefs); + const OUString& rName, const ScRange& rRange, std::set& rRefs); bool remove(const ScDPCache* p); }; @@ -358,8 +357,9 @@ public: com::sun::star::uno::Reference createRowSet( sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand); - void updateCache(sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand, - const ScDPDimensionSaveData* pDimData, std::set& rRefs); + void updateCache( + sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand, + std::set& rRefs); bool remove(const ScDPCache* p); }; diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index 169231a..653bc0c 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -2809,6 +2809,25 @@ struct FindInvalidRange : public std::unary_function } }; +void setGroupItemsToCache( ScDPCache& rCache, const std::set& rRefs ) +{ + // Go through all referencing pivot tables, and re-fill the group dimension info. + std::set::const_iterator itRef = rRefs.begin(), itRefEnd = rRefs.end(); + for (; itRef != itRefEnd; ++itRef) + { + const ScDPObject* pObj = *itRef; + const ScDPSaveData* pSave = pObj->GetSaveData(); + if (!pSave) + continue; + + const ScDPDimensionSaveData* pGroupDims = pSave->GetExistingDimensionData(); + if (!pGroupDims) + continue; + + pGroupDims->WriteToCache(rCache); + } +} + } bool ScDPCollection::SheetCaches::hasCache(const ScRange& rRange) const @@ -2926,8 +2945,7 @@ void ScDPCollection::SheetCaches::updateReference( } } -void ScDPCollection::SheetCaches::updateCache( - const ScRange& rRange, const ScDPDimensionSaveData* pDimData, std::set& rRefs) +void ScDPCollection::SheetCaches::updateCache(const ScRange& rRange, std::set& rRefs) { RangeIndexType::iterator it = std::find(maRanges.begin(), maRanges.end(), rRange); if (it == maRanges.end()) @@ -2947,12 +2965,15 @@ void ScDPCollection::SheetCaches::updateCache( } ScDPCache& rCache = *itCache->second; + + // Update the cache with new cell values. This will clear all group dimension info. rCache.InitFromDoc(mpDoc, rRange); - if (pDimData) - pDimData->WriteToCache(rCache); std::set aRefs(rCache.GetAllReferences()); rRefs.swap(aRefs); + + // Make sure to re-populate the group dimension info. + setGroupItemsToCache(rCache, rRefs); } bool ScDPCollection::SheetCaches::remove(const ScDPCache* p) @@ -3010,8 +3031,7 @@ size_t ScDPCollection::NameCaches::size() const } void ScDPCollection::NameCaches::updateCache( - const OUString& rName, const ScRange& rRange, const ScDPDimensionSaveData* pDimData, - std::set& rRefs) + const OUString& rName, const ScRange& rRange, std::set& rRefs) { CachesType::iterator itr = maCaches.find(rName); if (itr == maCaches.end()) @@ -3021,12 +3041,14 @@ void ScDPCollection::NameCaches::updateCache( } ScDPCache& rCache = *itr->second; + // Update the cache with new cell values. This will clear all group dimension info. rCache.InitFromDoc(mpDoc, rRange); - if (pDimData) - pDimData->WriteToCache(rCache); std::set aRefs(rCache.GetAllReferences()); rRefs.swap(aRefs); + + // Make sure to re-populate the group dimension info. + setGroupItemsToCache(rCache, rRefs); } bool ScDPCollection::NameCaches::remove(const ScDPCache* p) @@ -3171,7 +3193,7 @@ uno::Reference ScDPCollection::DBCaches::createRowSet( void ScDPCollection::DBCaches::updateCache( sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand, - const ScDPDimensionSaveData* pDimData, std::set& rRefs) + std::set& rRefs) { DBType aType(nSdbType, rDBName, rCommand); CachesType::iterator it = maCaches.find(aType); @@ -3204,12 +3226,12 @@ void ScDPCollection::DBCaches::updateCache( return; } - if (pDimData) - pDimData->WriteToCache(rCache); - comphelper::disposeComponent(xRowSet); std::set aRefs(rCache.GetAllReferences()); aRefs.swap(rRefs); + + // Make sure to re-populate the group dimension info. + setGroupItemsToCache(rCache, rRefs); } bool ScDPCollection::DBCaches::remove(const ScDPCache* p) @@ -3271,11 +3293,6 @@ sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set& if (!pDPObj) return STR_ERR_DATAPILOTSOURCE; - const ScDPSaveData* pSaveData = pDPObj->GetSaveData(); - const ScDPDimensionSaveData* pDimData = NULL; - if (pSaveData) - pDimData = pSaveData->GetExistingDimensionData(); - if (pDPObj->IsSheetData()) { // data source is internal sheet. @@ -3292,7 +3309,7 @@ sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set& // cache by named range ScDPCollection::NameCaches& rCaches = GetNameCaches(); if (rCaches.hasCache(pDesc->GetRangeName())) - rCaches.updateCache(pDesc->GetRangeName(), pDesc->GetSourceRange(), pDimData, rRefs); + rCaches.updateCache(pDesc->GetRangeName(), pDesc->GetSourceRange(), rRefs); else { // Not cached yet. Collect all tables that use this named @@ -3305,7 +3322,7 @@ sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set& // cache by cell range ScDPCollection::SheetCaches& rCaches = GetSheetCaches(); if (rCaches.hasCache(pDesc->GetSourceRange())) - rCaches.updateCache(pDesc->GetSourceRange(), pDimData, rRefs); + rCaches.updateCache(pDesc->GetSourceRange(), rRefs); else { // Not cached yet. Collect all tables that use this range as @@ -3324,7 +3341,7 @@ sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set& ScDPCollection::DBCaches& rCaches = GetDBCaches(); if (rCaches.hasCache(pDesc->GetCommandType(), pDesc->aDBName, pDesc->aObject)) rCaches.updateCache( - pDesc->GetCommandType(), pDesc->aDBName, pDesc->aObject, pDimData, rRefs); + pDesc->GetCommandType(), pDesc->aDBName, pDesc->aObject, rRefs); else { // Not cached yet. Collect all tables that use this range as -- 1.8.4.2