MDL-72246 core_completion: Only fetch other completion data on requested
commit70cc41eec88bfe26e45bab84d8d3996f48eab881
authorAndrew Nicols <andrew@nicols.co.uk>
Wed, 2 Feb 2022 08:10:59 +0000 (2 16:10 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 8 Feb 2022 03:35:23 +0000 (8 11:35 +0800)
treebd4ce5e9cc3e8c4a21f96d49a6f0e6e7e2f2dd5b
parentadc61dddc32222323410eee94036d1d14058caef
MDL-72246 core_completion: Only fetch other completion data on requested

Prior to this patch, the code was fetching all completion data for all
activities in a course, even when the activity was not requested. This
leads to recursion issues as the data has not been added to the cache
before this operation occurs.

To handle this situation, only the requested CM is fetched in full, and
a boolean flag is used to store whether the full data has been fetched.

When returning a partially fetched value from the cache, the flag is
used to determine whether more data must be fetched, and the cache
updated.

The flag is filtered out before the value is returned.

Note: Many of the tests were updated as these were inspecting private
features of the API which should not really be tested.
lib/completionlib.php
lib/tests/completionlib_test.php