Skip to content
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

make sure summary rows are serialized with their in-db subtable ID and not in memory one #17831

Merged
merged 2 commits into from Jul 30, 2021

Conversation

diosmosis
Copy link
Member

Description:

As title, for summary rows we are currently serializing the row with the incorrect subtable ID, causing it not to load w/ the subtable.

Review

  • Functional review done
  • Potential edge cases thought about (behavior of the code with strange input, with strange internal state or possible interactions with other Matomo subsystems)
  • Usability review done (is anything maybe unclear or think about anything that would cause people to reach out to support)
  • Security review done see checklist
  • Code review done
  • Tests were added if useful/possible
  • Reviewed for breaking changes
  • Developer changelog updated if needed
  • Documentation added if needed
  • Existing documentation updated if needed

@diosmosis diosmosis added Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review labels Jul 28, 2021
@diosmosis diosmosis added this to the 4.4.1 milestone Jul 28, 2021
Copy link
Member

@tsteur tsteur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diosmosis does this mean maybe it also has an impact on some other usages of getRowsWithoutSummaryRow() and getSummaryRow()?

We separated this at some point as getRows() was causing memory issues.

Do you know how this later detects the summary row in methods like addRowsFromSerializedArray where it relied on having the summary row ID?

I'm not sure I fully understand the issue yet.

@diosmosis
Copy link
Member Author

@tsteur from the blame it looks like we were never serializing the summary row. The specific line was last changed seven years ago: https://github.com/matomo-org/matomo/blame/b77e5ff594cdae59862dd4d863220baffc200bec/core/DataTable.php#L1323

And the summaryRow property has been there for nine years. So I think this has always been an issue.

Do you know how this later detects the summary row in methods like addRowsFromSerializedArray where it relied on having the summary row ID?

We serialize the rows array which associates id w/ row data, so we simply unserialize it. The subtable ID after directly unserializing is used to get the subtable in the database. So it detects it because of the ID we serialize it with.

I'm not sure if this answers your questions...

Copy link
Member

@tsteur tsteur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand now 👍 and the ID is afterwards still the same because the summary row has that ID anyway. This way we export also subtables of summary rows.

I do remember in https://github.com/matomo-org/matomo/pull/7577/files#diff-6542f24c55ecdc44d36de949a6c0be12f5a4e9ebcb064ae5a78e3a8cdb6e1b28R1269 years back making changes there for improving performance.

Just to be safe we're not making things slower would it be too bad to duplicate the code there (as it's executed a lot with a lot of data) like

        if (isset($this->summaryRow)) {
            if (isset($consecutiveSubtableIds[self::ID_SUMMARY_ROW])) {
                $backup = $row->subtableId;
                $row->subtableId = $consecutiveSubtableIds[self::ID_SUMMARY_ROW];
                $rows[self::ID_SUMMARY_ROW] =  $this->summaryRow->export();
                $row->subtableId = $backup;
            } else {
                $rows[self::ID_SUMMARY_ROW] =  $this->summaryRow->export();
            }
        }

@diosmosis
Copy link
Member Author

@tsteur 👍 that makes sense, to avoid the array operation

@diosmosis
Copy link
Member Author

applied review feedback

@tsteur tsteur merged commit e0b50ad into 4.x-dev Jul 30, 2021
@tsteur tsteur deleted the correct-summary-row-subtable-serialization branch July 30, 2021 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants