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

[Cleanup] Make DBRowProvisioner use Database class #9509

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

driusan
Copy link
Collaborator

@driusan driusan commented Dec 12, 2024

This updates DBRowProvisioner to remove the strval (and fixes #9335).

After doing that, it became clear that the inner class could be replaced by a generator while still fulfilling the contract of returning a \Traversable. Doing this made it more obvious that since #9334, pselect could be used directly while maintaining the lazy evaluation instead of bypassing the Database object to use the PDO directly. However this required injecting a LorisInstance object to the constructor to get the database connection.

With access to the LorisInstance object, the DBRowProvisioner can also get a new database connection and disable query buffering to lazily retrieve rows since PR #9344. This may theoretically improve performance and memory usage on large provisioners but has not been tested. (Performance did not decrease in raisinbread but it is not a large dataset where it would be noticeable.)

@driusan driusan added Cleanup PR or issue introducing/requiring at least one clean-up operation Language: PHP PR or issue that update PHP code Category: Refactor PR or issue that aims to improve the existing code Category: Perfomance Issue or PR that aims to report or improve perfomance labels Dec 12, 2024
@@ -1055,12 +1061,7 @@ class TimePoint implements \LORIS\StudyEntities\AccessibleResource,
);

$provisioner = $provisioner->filter($filter);

$traversable = (new \LORIS\Data\Table())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This part didn't seem to be useful, so I verified and removed while testing.

@@ -83,50 +83,12 @@ abstract public function getInstance($row) : DataInstance;
*/
public function getAllInstances() : \Traversable
{
$DB = (\NDB_Factory::singleton())->database();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the bulk of the PR. The rest is mostly just propagating LorisInstance objects places that didn't have it.

@driusan driusan force-pushed the NoProvisionerStrVal branch from 3732d13 to 04ddf5c Compare December 12, 2024 18:30
@@ -324,7 +324,7 @@ function testFilter()
self::$display,
self::$clearFilter,
'0',
'2 rows'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test was failing and when I investigated I don't see any rows with a value of "0" in RB and nothing inserted from the test, so I'm not sure where "2" was coming from and I think it's an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change it to test '4300' with '1 rows' so that the test is still testing the filter? I feel like testing for no results is less foolproof, and the max age test covers that below anyway

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good idea. I'll try.

@driusan driusan force-pushed the NoProvisionerStrVal branch 2 times, most recently from 23420d6 to 4411abd Compare December 12, 2024 19:49
@driusan driusan force-pushed the NoProvisionerStrVal branch from 4411abd to 2f23574 Compare December 13, 2024 13:34
@skarya22 skarya22 self-assigned this Dec 13, 2024
@skarya22 skarya22 self-requested a review December 13, 2024 20:27
Comment on lines +1117 to +1123
public function getDicomTars(\LORIS\LorisInstance $loris, \User $user): iterable
{
$provisioner = new \LORIS\api\provisioners\VisitDicomsRowProvisioner($this);
$traversable = (new \LORIS\Data\Table())
->withDataFrom($provisioner)
->getRows($user);

return iterator_to_array($traversable);
$provisioner = new \LORIS\api\provisioners\VisitDicomsRowProvisioner(
$loris,
$this
);
return iterator_to_array($provisioner->execute($user));
Copy link
Contributor

Choose a reason for hiding this comment

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

This was changed to return type iterator but returns iterator_to_array, so isn't return type still an array?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right. I originally didn't have the iterator_to_array and it was working but then I had to include it to get the phan (or phpstan, can't remember) tests to pass. It's probably kind of pointless now.

@@ -324,7 +324,7 @@ function testFilter()
self::$display,
self::$clearFilter,
'0',
'2 rows'
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change it to test '4300' with '1 rows' so that the test is still testing the filter? I feel like testing for no results is less foolproof, and the max age test covers that below anyway

@skarya22 skarya22 assigned driusan and unassigned skarya22 Dec 13, 2024
@skarya22 skarya22 added the State: Needs rebase PR that needs to be rebased to proceed (conflicts, wrong branch...) label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Perfomance Issue or PR that aims to report or improve perfomance Category: Refactor PR or issue that aims to improve the existing code Cleanup PR or issue introducing/requiring at least one clean-up operation Language: PHP PR or issue that update PHP code State: Needs rebase PR that needs to be rebased to proceed (conflicts, wrong branch...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove strval from src/Data/Provisioners/DBRowProvisioner.php
2 participants