-
Notifications
You must be signed in to change notification settings - Fork 359
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
Add option to use resumptionToken in REST #4225
Open
LuomaJuha
wants to merge
4
commits into
vufind-org:dev
Choose a base branch
from
LuomaJuha:add-cursor-rest-api-search
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+403
−97
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a54d957
Added cursor possibility for rest api search
LuomaJuha 9312561
Adjusted openapi.phtml
LuomaJuha 4fe477d
Added apiexception for filtering exceptions, take facets ini file fro…
LuomaJuha b7ccf23
Update module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php
LuomaJuha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
106 changes: 106 additions & 0 deletions
106
module/VuFind/src/VuFind/ResumptionToken/ResumptionTokenTrait.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
/** | ||
* Resumption token trait. | ||
* | ||
* PHP version 8 | ||
* | ||
* Copyright (C) The National Library 2024. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* @category VuFind | ||
* @package Controller | ||
* @author Juha Luoma <[email protected]> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development:plugins:controllers Wiki | ||
*/ | ||
|
||
namespace VuFind\ResumptionToken; | ||
|
||
use VuFind\Db\Entity\OaiResumptionEntityInterface; | ||
use VuFind\Db\Service\OaiResumptionServiceInterface; | ||
|
||
/** | ||
* Resumption token trait. | ||
* | ||
* @category VuFind | ||
* @package Controller | ||
* @author Juha Luoma <[email protected]> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development:plugins:controllers Wiki | ||
*/ | ||
trait ResumptionTokenTrait | ||
{ | ||
/** | ||
* Resumption service for managing resumption tokens. | ||
* | ||
* @var OaiResumptionServiceInterface | ||
*/ | ||
protected OaiResumptionServiceInterface $resumptionService; | ||
|
||
/** | ||
* Set resumption service | ||
* | ||
* @param OaiResumptionServiceInterface $resumptionService Resumption service | ||
* | ||
* @return void | ||
*/ | ||
public function setResumptionService(OaiResumptionServiceInterface $resumptionService): void | ||
demiankatz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$this->resumptionService = $resumptionService; | ||
} | ||
|
||
/** | ||
* Generate and return a new resumption token | ||
* | ||
* @param array $params Params to be saved for the resumption token | ||
* @param int $cursor Cursor to be saved for the resumption token | ||
* @param string $cursorMark Cursor mark to be saved for the resumption token | ||
* | ||
* @return OaiResumptionEntityInterface | ||
*/ | ||
public function createResumptionToken( | ||
array $params, | ||
int $cursor, | ||
string $cursorMark | ||
): OaiResumptionEntityInterface { | ||
$params['cursor'] = $cursor; | ||
$params['cursorMark'] = $cursorMark; | ||
$expire = time() + 24 * 60 * 60; | ||
demiankatz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return $this->resumptionService->createAndPersistToken($params, $expire); | ||
} | ||
|
||
/** | ||
* Load parameters associated with a resumption token. | ||
* | ||
* @param string $token The resumption token to look up | ||
* | ||
* @return array|false Parameters associated with token or false if invalid or expired | ||
demiankatz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
protected function loadResumptionToken(string $token): array|false | ||
{ | ||
// Clean up expired records before doing our search: | ||
$this->resumptionService->removeExpired(); | ||
|
||
// Load the requested token if it still exists: | ||
if ($row = $this->resumptionService->findToken($token)) { | ||
parse_str($row->getResumptionParameters(), $params); | ||
return $params; | ||
} | ||
|
||
// If we got this far, the token is invalid or expired: | ||
return false; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.
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.
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 we specify the default value (which currently appears to be 1000) here? And is it possible that limit is too high? Even if the performance of the cursor improves speed, don't we still need to worry about potentially running out of memory if the index contains large records?
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.
Adjusted the comment and set the default value for 200. (Modifiable in searches.ini)
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.
I would suggest adding "(default = 200)" to the comments here so users know what they will get if they don't override the setting through the configuration.
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 also worth adding a note to maxLimit above indicating that it only applies to results without resumption tokens.