-
Notifications
You must be signed in to change notification settings - Fork 186
[dataquery] Add ability to retrieve results of previous run from API #9301
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
Conversation
function ( | ||
$candid, | ||
$rowsArray, | ||
/* @phan-suppress-next-line PhanUnusedClosureParameter */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closure signature needs to match the callback of DataIteratorBinaryStream, so the unused parameter can't be removed.
* | ||
* @return ResponseInterface | ||
*/ | ||
public function countResults(\User $user) : ResponseInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function was unused in this class, so I removed it while I was cleaning up the code.
modules/dataquery/php/endpoints/queries/query/run/run.class.inc
Outdated
Show resolved
Hide resolved
@driusan needs to have the conflict resolved but otherwise this is working well! |
This implements the endpoint that is listed as "aspirational" in the dataquery api schema to load the results of a previously run query. It was originally left out for fear of performance issues but with this implementation performance seems to be comparable to without it. This does not implement a frontend to reload query results, but the API functionality is useful for eg api callbacks that want to process the results of a query without the need to re-run it (and the possibility to get different results.)
2e51649
to
ef357da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running a query from this PR isn't working. Getting the following error:
[Wed Jan 22 11:00:02.344866 2025] [php:error] [pid 7561] [client ::1:42036] PHP Fatal error: Uncaught TypeError: LORIS\dataquery\QueryRun::getCandidates(): Return value must be of type array, Generator returned in /var/www/loris/modules/dataquery/php/queryrun.class.inc:103\nStack trace:\n#0 /var/www/loris/modules/dataquery/php/querydataprovisioner.class.inc(51): LORIS\dataquery\QueryRun->getCandidates()\n#1 /var/www/loris/src/Data/ProvisionerInstance.php(116): LORIS\dataquery\QueryDataProvisioner->getAllInstances()\n#2 /var/www/loris/modules/dataquery/php/querydataprovisioner.class.inc(41): LORIS\Data\ProvisionerInstance->execute()\n#3 /var/www/loris/modules/dataquery/php/endpoints/queries/query/run.class.inc(70): LORIS\dataquery\QueryDataProvisioner->execute()\n#4 /var/www/loris/modules/dataquery/php/endpoints/queries/query/run.class.inc(47): LORIS\dataquery\endpoints\queries\query\Run->runQuery()\n#5 /var/www/loris/src/Middleware/Compression.php(36): LORIS\dataquery\endpoints\queries\query\Run->handle()\n#6 /var/www/loris/modules/dataquery/php/queries.class.inc(83): LORIS\Middleware\Compression->process()\n#7 /var/www/loris/src/Middleware/UserPageDecorationMiddleware.php(248): LORIS\dataquery\Queries->handle()\n#8 /var/www/loris/src/Middleware/PageDecorationMiddleware.php(59): LORIS\Middleware\UserPageDecorationMiddleware->process()\n#9 /var/www/loris/php/libraries/NDB_Page.class.inc(726): LORIS\Middleware\PageDecorationMiddleware->process()\n#10 /var/www/loris/php/libraries/Module.class.inc(322): NDB_Page->process()\n#11 /var/www/loris/src/Middleware/ResponseGenerator.php(51): Module->handle()\n#12 /var/www/loris/src/Middleware/AuthMiddleware.php(64): LORIS\Middleware\ResponseGenerator->process()\n#13 /var/www/loris/src/Router/ModuleRouter.php(75): LORIS\Middleware\AuthMiddleware->process()\n#14 /var/www/loris/src/Middleware/ExceptionHandlingMiddleware.php(55): LORIS\Router\ModuleRouter->handle()\n#15 /var/www/loris/src/Router/BaseRouter.php(138): LORIS\Middleware\ExceptionHandlingMiddleware->process()\n#16 /var/www/loris/src/Middleware/ResponseGenerator.php(51): LORIS\Router\BaseRouter->handle()\n#17 /var/www/loris/src/Middleware/ContentLength.php(53): LORIS\Middleware\ResponseGenerator->process()\n#18 /var/www/loris/htdocs/index.php(74): LORIS\Middleware\ContentLength->process()\n#19 {main}\n thrown in /var/www/loris/modules/dataquery/php/queryrun.class.inc on line 103, referer: http://localhost:8080/dataquery/
@CamilleBeau I fixed the error (and a couple other introduced by the rebase). Should be ready now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running a query, saving a query, filters, and accessing previous queries from API are all working now.
Just a couple of notes on the code. There are tests failing as well
|
||
} | ||
} | ||
set_time_limit(300); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be configurable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe?
I think it can just be removed. Our documentation says to set max_execution_time
to 10800 to support large files which is the php config setting that php would fall back on.
public function queryResults(\User $user) : ResponseInterface | ||
{ | ||
$db = $this->loris->getDatabaseConnection(); | ||
// FIXME: Check permissions. Check if count(*) > 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Permission check needed still?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops.. you're right. That's still needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
modules/dataquery/php/endpoints/queries/query/run/run.class.inc
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the tests I ran are passing now for the saved queries accessed from API, running queries, saving queries, and accessing queries / data from a user with limited access. One thing to note is that you can have access to another user's private query using the API URL as long as you have the access to all of the fields in the query. If this is intended then all looks good!
This implements the endpoint that is listed as "aspirational" in the
dataquery api schema to load the results of a previously run query.
It was originally left out for fear of performance issues but with
this implementation performance seems to be comparable to without
it.
This does not implement a frontend to reload query results, but
the API functionality is useful for i.e. api callbacks that want
to process the results of a query without the need to re-run
it (and the possibility to get different results.)