Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Speed up retrieval of membership data by using a SELECT query #559

Merged
merged 11 commits into from
Aug 9, 2019

Conversation

pfrenssen
Copy link
Contributor

This is the final PR for #487. This replaces the loading of the (cached) OgMembership entities with a direct SELECT query if a SQL database is used for storing the entities. The original approach is kept as a fallback for NoSQL databases as was suggested in #487.

On my system this shaves off another ~60ms of the wall time for a user with 1140 groups since the full entities no longer need to be retrieved from cache. This brings the total time down to ~11ms.

This is built on top of #555 so includes all commits from that PR. This is blocked until that PR is merged.

@pfrenssen pfrenssen added Drupal 8 Performance Performance issues or improvements Postponed labels Jul 26, 2019
@pfrenssen
Copy link
Contributor Author

I'm getting failures when running this on my large project. I am investigating. It looks like the correct cache contexts are not returned if the user is a "normal" member, only when they have a dedicated role such as administrator.

This ensures that the SQL-based calculation of the cache context gives the
same results as the membership based one.
@pfrenssen
Copy link
Contributor Author

All tests are green now, here and in my project :)

Copy link
Contributor

@idimopoulos idimopoulos left a comment

Choose a reason for hiding this comment

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

I have checked both this and the #555 and they both work fine. However, as I noted in the other PR, I do not see the ::getRolesIds being tested anywhere.
In this test everything is prophesied (I am not very familiar with UnitTests but I see that you are programming what will be returned) and the only other case where ::getRolesIds is called is a test where it can fail if wrong information are returned. Can we have a small addition in the OgMembershipTest Kernel test (or even a UnitTest if you are more comfortable with) that actually test the return of the method?
Or at least point me to where it is if I did not find it.

@pfrenssen
Copy link
Contributor Author

Yes I agree that a KernelTest for the SQL version would be better. There was a bug in the query and I adapted the test, but it is not very reliable in this state. The test only really assures that the query is doing certain conditions but does not really guarantee that it won't regress if for example the conditions change or a new condition is added.

@MPParsley
Copy link
Collaborator

@pfrenssen, should this still be marked as postponed?

@pfrenssen
Copy link
Contributor Author

Yes this is still postponed on #555 which should go in first. But #555 is now near completion, the latest remarks were addressed. There were some failures but they seem to be infrastructure related.

For this PR I would like to convert the unit test for the query into a kernel test so that this is more reliably tested. I can work on this today, this is back in sprint for our project.

@pfrenssen
Copy link
Contributor Author

#555 is in so this is unblocked!

By executing the query against a real database instance rather than using a
mocked result we can better assert that the functionality is actually working as
expected.
Co-Authored-By: Maarten Segers <MPParsley@users.noreply.github.com>
@pfrenssen
Copy link
Contributor Author

Awesome, this concludes the work on #487. With this in the lookup of the cache context is around 14x faster. For more details on the speed improvements see this comment: #487 (comment)

@pfrenssen pfrenssen merged commit 851cf68 into 8.x-1.x Aug 9, 2019
@pfrenssen pfrenssen deleted the query-membership-data branch August 9, 2019 05:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Drupal 8 Performance Performance issues or improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants