llms_is_user_enrolled always return false for non existing or unlogged users#2315
Merged
ideadude merged 2 commits intoMar 1, 2023
Conversation
2081d37 to
05baf66
Compare
Contributor
Author
|
@ideadude |
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
While looking at https://github.com/gocodebox/private-issues/issues/63
I realized that we "try" to query the DB looking for enrollments even for not logged in users, and generally for non existing users (e.g. deleted users). In this PR I just return immediately false when checking for enrollments of non existing users when using
llms_is_user_enrolled().This is technically a breaking change (so will ideally push the next LifterLMS version to 8.0), as we're changing the default behavior of a public function although we internally always used that assuming that the user was existing: with that function you could theoretically query the enrollment status of a student in a course even if the student was deleted.
Also consider that in the future we want to delete the enrollment related data of a user upon its removal (see #940 bullet Delete data from lifterlms_user_postmeta table). Maybe we want take the occasion and implement a fix for #940 so to release a new major version including this PR?
This PR will also basically fix https://github.com/gocodebox/private-issues/issues/63
Also this PR has some perfomance impact (improvements) on not logged in users visiting e.g. courses or membership catalogs: for each course/membership in the current catalog page we check whether or not the current user (user with ID 0 for non logged in users) is enrolled in the course/membership performing a custom and not simple DB query (although on an index of the table).
How has this been tested?
manually and existing unit tests
Types of changes
Breaking change (fix or feature that would cause existing functionality to not work as expected) -->
Checklist: