-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Implement flat-first archiving for Action reports to improve limiting and memory consumption #24191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sgiehl
wants to merge
20
commits into
5.x-dev
Choose a base branch
from
archivetest
base: 5.x-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c9ca289
implement flat archiving logic
sgiehl 4eeca25
move flat-first archiving behind config flag and implement handling f…
sgiehl 2929372
code improvements & tests
sgiehl 46a898d
Move build from flat logic to RecordBuilder
sgiehl ccd77f5
further improvements
sgiehl d7c971a
move code to reusable helper methods
sgiehl 4ab2572
more fixes and tests
sgiehl 916943c
simplify code
sgiehl e704d52
code simplification
sgiehl 5e23632
more cleanup
sgiehl 6ecb4fe
Ensure to correctly archive if only flat record is requested
sgiehl 9278036
apply some review feedback
sgiehl 1869ffd
deduplicate/refactor code
sgiehl d9bf263
use constants for leaf markers
sgiehl 2e549bd
avoid reading blobs more than once for mixed archiving approach
sgiehl 675cfeb
Use canonical path labels for flat-first action archives to keep hier…
sgiehl d8d7dfd
Implemented a memory-reduction step for non-day flat-first hierarchy …
sgiehl a30cf85
Improve performance of mixed table aggregation (old hierarchy tables…
sgiehl 315154e
removes revised methods
sgiehl f16ffa5
release serialized-blob strings after insertion
sgiehl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Matomo - free/libre analytics platform | ||
| * | ||
| * @link https://matomo.org | ||
| * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
| */ | ||
|
|
||
| namespace Piwik\ArchiveProcessor; | ||
|
|
||
| use Piwik\Common; | ||
| use Piwik\DataTable; | ||
| use Piwik\DataTable\Row; | ||
|
|
||
| /** | ||
| * Internal helper for aggregating blob rows into a DataTable. | ||
| * | ||
| * @internal | ||
| */ | ||
| final class BlobTableAggregator | ||
| { | ||
| /** | ||
| * @param iterable<array{name: string, date1: string, date2: string, value: string}> $archiveDataRows | ||
| * @param callable(DataTable):void $renameColumnsCallback | ||
| * @param callable(array{name: string, date1: string, date2: string, value: string}):bool|null $shouldIncludeRow | ||
| * @param callable(string, int):void|null $onMissingParentTable | ||
| * @return array{0: DataTable, 1: bool} | ||
| */ | ||
| public static function aggregateBlobRows( | ||
| iterable $archiveDataRows, | ||
| string $recordName, | ||
| ?array $columnsAggregationOperation, | ||
| callable $renameColumnsCallback, | ||
| ?callable $shouldIncludeRow = null, | ||
| ?callable $onMissingParentTable = null | ||
| ): array { | ||
| // maps period & subtable ID in database to the Row instance in $result that subtable should be added to | ||
| // [$row['date1'].','.$row['date2']][$tableId] = $row in $result | ||
| $tableIdToResultRowMapping = []; | ||
| $result = new DataTable(); | ||
| $hasRows = false; | ||
|
|
||
| if (!empty($columnsAggregationOperation)) { | ||
| $result->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnsAggregationOperation); | ||
| } | ||
|
|
||
| foreach ($archiveDataRows as $archiveDataRow) { | ||
| if ($shouldIncludeRow !== null && !$shouldIncludeRow($archiveDataRow)) { | ||
| continue; | ||
| } | ||
|
|
||
| $hasRows = true; | ||
| $period = $archiveDataRow['date1'] . ',' . $archiveDataRow['date2']; | ||
| $tableId = $archiveDataRow['name'] === $recordName | ||
| ? null | ||
| : self::parseSubtableIdFromBlobName($archiveDataRow['name']); | ||
|
|
||
| $blobTable = DataTable::fromSerializedArray($archiveDataRow['value']); | ||
| $blobTable->filter(function (DataTable $table) use ($renameColumnsCallback) { | ||
| $renameColumnsCallback($table); | ||
| }); | ||
|
|
||
| if ($tableId === null) { | ||
| $tableToAddTo = $result; | ||
| } elseif (empty($tableIdToResultRowMapping[$period][$tableId])) { | ||
| if ($onMissingParentTable !== null) { | ||
| $onMissingParentTable($period, $tableId); | ||
| } | ||
| Common::destroy($blobTable); | ||
| continue; | ||
| } else { | ||
| $rowToAddTo = $tableIdToResultRowMapping[$period][$tableId]; | ||
| if (!$rowToAddTo->getIdSubDataTable()) { | ||
| $newTable = new DataTable(); | ||
| if (!empty($columnsAggregationOperation)) { | ||
| $newTable->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnsAggregationOperation); | ||
| } | ||
| $rowToAddTo->setSubtable($newTable); | ||
| } | ||
|
|
||
| $tableToAddTo = $rowToAddTo->getSubtable(); | ||
| } | ||
|
|
||
| $tableToAddTo->addDataTable($blobTable); | ||
|
|
||
| foreach ($blobTable->getRows() as $blobTableRow) { | ||
| $label = $blobTableRow->getColumn('label'); | ||
| $subtableId = $blobTableRow->getIdSubDataTable(); | ||
| if (empty($subtableId)) { | ||
| continue; | ||
| } | ||
|
|
||
| $rowToAddTo = $tableToAddTo->getRowFromLabel($label); | ||
| if ($rowToAddTo instanceof Row) { | ||
| $tableIdToResultRowMapping[$period][$subtableId] = $rowToAddTo; | ||
| } | ||
| } | ||
|
|
||
| Common::destroy($blobTable); | ||
| } | ||
|
|
||
| return [$result, $hasRows]; | ||
| } | ||
|
|
||
| public static function parseSubtableIdFromBlobName(string $recordName): ?int | ||
| { | ||
| $parts = explode('_', $recordName); | ||
| $id = end($parts); | ||
|
|
||
| if (!is_numeric($id)) { | ||
| return null; | ||
| } | ||
|
|
||
| return (int) $id; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.