From 29999ea70626a4b1dd312ad6e07f1131b6449f93 Mon Sep 17 00:00:00 2001 From: Tamás Zolnai Date: Tue, 27 Sep 2016 05:08:51 +0200 Subject: tdf#102694, bnc#957991: Improve pivot cache reading performance This is an aggregated patch, containing all related changes on master. Fixes some functional issues also next to the performance problem and add all new test cases related this bug fix. bnc#957991: Improve pivot cache reading performance Performance problem was caused by grouping. Pivot tables with the same source are linked to each other by the pivot cache and so all the pivot tables were updated when one group was added to one of the tables. This code change first of all fixes a functional issue: group name was wrongly imported and so pivot tables using group fields were broken. This caused by calling RefreshPivotTableGroups() on a pivot table which is not part of the cache yet and so update was not called on this table. Calling ReloadGroupTableData() solve this problem. Second part of the codechange is about the consistency of the pivot cache. We have an invariant in this code to have the same groups for tabels with the same source. To keep this invariant we update every newly inserted tables adding the neccessary groups. The performance improvement here is that until the table is not part of the cache, it does not updates other tables. Group syncronization is done when the table is inserted to the ScDPCollection. (cherry picked from commit 3b64a198568d5b2bb14066581aca112cc6182fd7) This parameter can be const. (cherry picked from commit b905116dc41a4101e4e44d39d946bbba6a3a334d) Test the case for pivot tables sharing a group Fixed with 3b64a198568d5b2bb14066581aca112cc6182fd7 (cherry picked from commit 049d2ffd329f88934a92b72e4ec650ea46bf8c61) Test XLSX import of date groups (cherry picked from commit f1a97fab957629d617b0b0ad44de5beb3d343f5c) Test XLSX import of number groups (cherry picked from commit 93098854c2d2b814a21161bd88071918cb382e87) Pivot tables: Fix wrong group field number in cache getCache should not append new group fields to the cache, but use those which are stored in the dimension data. (cherry picked from commit 7e1fd9aa86ab8d5e86f35df8615f438a3383af98) Pivot tables: Fix XLSX import of nested date groups Same fix which was added for other kind of groups: f697d7aa5c26f9fcfd717b76a4827a5bcb38325e (cherry picked from commit 9d19634c8e719a80674ca4b3dfc3c7e49f049e5b) Pivot table XLSX import: PivotCache is not handled as a const object. (cherry picked from commit db481dd30521f9ce498873cdc945cf9544bf983c) tdf#102694, bnc#957991: Improve pivot cache reading performance When two or more tables have the same source data, then the grouping of source fields are shared between these tables, so don't need to import these grouping for each tables. The added code checkes whether we already imported the group fields and don't create them again using API functions, but apply the exisiting groups of an other table sharing the source. (cherry picked from commit 03a1143cc75161dab56b20f1ab9e723ddd0caa8e) Add better comment for this function. (cherry picked from commit 97ebbb892993507fe19ca069534015637fde497b) Change-Id: I04d81295491c4c0f351200670f9ebdae5644f858 Reviewed-on: https://gerrit.libreoffice.org/30048 Tested-by: Jenkins Reviewed-by: Andras Timar --- sc/source/core/data/dpobject.cxx | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'sc/source/core/data/dpobject.cxx') diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index 531ab8176a0b..db529fbdff4c 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -2847,7 +2847,10 @@ const ScDPCache* ScDPCollection::SheetCaches::getCache(const ScRange& rRange, co } if (pDimData) + { + (itCache->second)->ClearGroupFields(); pDimData->WriteToCache(*itCache->second); + } return itCache->second.get(); } @@ -3440,6 +3443,71 @@ bool ScDPCollection::ReloadGroupsInCache(ScDPObject* pDPObj, std::set& aTable : maTables) + { + const ScDPObject& rRefObj = *aTable.get(); + + if (&rRefObj == &rDPObj) + continue; + + if (rDPObj.IsSheetData()){ + if(!rRefObj.IsSheetData()) + continue; + + const ScSheetSourceDesc* pDesc = rDPObj.GetSheetDesc(); + const ScSheetSourceDesc* pRefDesc = rRefObj.GetSheetDesc(); + if (pDesc == nullptr || pRefDesc == nullptr) + continue; + + if (pDesc->HasRangeName()) + { + if (!pRefDesc->HasRangeName()) + continue; + + if (pDesc->GetRangeName() == pRefDesc->GetRangeName()) + { + *pGroups = rRefObj.GetSaveData()->GetExistingDimensionData(); + return true; + } + } + else + { + if (pRefDesc->HasRangeName()) + continue; + + if (pDesc->GetSourceRange() == pRefDesc->GetSourceRange()) + { + *pGroups = rRefObj.GetSaveData()->GetExistingDimensionData(); + return true; + } + } + } + else if (rDPObj.IsImportData()) + { + if (!rRefObj.IsImportData ()) + continue; + + const ScImportSourceDesc* pDesc = rDPObj.GetImportSourceDesc(); + const ScImportSourceDesc* pRefDesc = rRefObj.GetImportSourceDesc(); + if (pDesc == nullptr || pRefDesc == nullptr) + continue; + + if (pDesc->aDBName.equals(pRefDesc->aDBName) && + pDesc->aObject.equals(pRefDesc->aObject) && + pDesc->GetCommandType() == pRefDesc->GetCommandType()) + { + *pGroups = rRefObj.GetSaveData()->GetExistingDimensionData(); + return true; + } + + } + } + return false; +} + + void ScDPCollection::DeleteOnTab( SCTAB nTab ) { maTables.erase( std::remove_if(maTables.begin(), maTables.end(), MatchByTable(nTab)), maTables.end()); @@ -3619,6 +3687,18 @@ bool ScDPCollection::InsertNewTable(ScDPObject* pDPObj) return true; } +bool ScDPCollection::HasTable(const ScDPObject* pDPObj) const +{ + for (const std::unique_ptr& aTable : maTables) + { + if (aTable.get() == pDPObj) + { + return true; + } + } + return false; +} + ScDPCollection::SheetCaches& ScDPCollection::GetSheetCaches() { return maSheetCaches; -- cgit v1.2.3