Skip to content

Commit

Permalink
Microoptimized search request.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Nov 4, 2018
1 parent b9bb01a commit dc16394
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
33 changes: 12 additions & 21 deletions application/src/Api/Adapter/AbstractEntityAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Omeka\Api\Exception;
use Omeka\Api\Request;
use Omeka\Api\Response;
use Omeka\Entity\User;
use Omeka\Entity\EntityInterface;
use Omeka\Entity\User;
use Omeka\Stdlib\ErrorStore;
use Zend\EventManager\Event;

Expand Down Expand Up @@ -172,26 +172,17 @@ public function search(Request $request)
$query = $request->getContent();

// Set default query parameters
if (!isset($query['page'])) {
$query['page'] = null;
}
if (!isset($query['per_page'])) {
$query['per_page'] = null;
}
if (!isset($query['limit'])) {
$query['limit'] = null;
}
if (!isset($query['offset'])) {
$query['offset'] = null;
}
if (!isset($query['sort_by'])) {
$query['sort_by'] = null;
}
if (isset($query['sort_order'])
&& in_array(strtoupper($query['sort_order']), ['ASC', 'DESC'])
) {
$query['sort_order'] = strtoupper($query['sort_order']);
} else {
$defaultQuery = [
'page' => null,
'per_page' => null,
'limit' => null,
'offset' => null,
'sort_by' => null,
'sort_order' => 'ASC',
];
$query += $defaultQuery;
$query['sort_order'] = strtoupper($query['sort_order']);
if (!in_array($query['sort_order'], ['ASC', 'DESC'])) {
$query['sort_order'] = 'ASC';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,13 @@ public function values()
public function value($term, array $options = [])
{
// Set defaults.
if (!isset($options['type'])) {
$options['type'] = null;
}
if (!isset($options['all'])) {
$options['all'] = false;
}
if (!isset($options['default'])) {
$options['default'] = null;
}
if (!isset($options['lang'])) {
$options['lang'] = null;
}
$defaultOptions = [
'type' => null,
'all' => false,
'default' => null,
'lang' => null,
];
$options += $defaultOptions;

if (!$this->getAdapter()->isTerm($term)) {
return $options['default'];
Expand Down

0 comments on commit dc16394

Please sign in to comment.