Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Use setLimit() to set query limit (#25981)
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkyKZ authored and HLeithner committed Aug 26, 2019
1 parent 236399f commit 803d2f2
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion administrator/components/com_finder/Indexer/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ protected function getItem($id)
protected function getItems($offset, $limit, $query = null)
{
// Get the content items to index.
$this->db->setQuery($this->getListQuery($query), $offset, $limit);
$this->db->setQuery($this->getListQuery($query)->setLimit($limit, $offset));
$items = $this->db->loadObjectList(null, Result::class);

foreach ($items as $item)
Expand Down
3 changes: 2 additions & 1 deletion administrator/components/com_finder/Indexer/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ public static function getNodeByTitle($branch, $title)
->where('t2.title = ' . $db->quote($branch));

// Get the node.
$db->setQuery($query, 0, 1);
$query->setLimit(1);
$db->setQuery($query);

return $db->loadObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public function search()
}

// Consider the limitstart according to the 'more' parameter and load the results.
$db->setQuery($query, $limitstart, 10);
$query->setLimit(10, $limitstart);
$db->setQuery($query);
$results['results'] = $db->loadObjectList();

// Check whether there are more results than already loaded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public function getExtensionName($eid)
->from($db->quoteName('#__extensions'))
->where($db->quoteName('extension_id') . ' = ' . (int) $eid);

$db->setQuery($query, 0, 1);
$query->setLimit(1);
$db->setQuery($query);

$extension = $db->loadObject();

Expand Down
3 changes: 2 additions & 1 deletion components/com_contact/Model/ContactModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ protected function buildContactExtendedData($contact)
}
}

$db->setQuery($query, 0, (int) $articles_display_num);
$query->setLimit((int) $articles_display_num);
$db->setQuery($query);
$contact->articles = $db->loadObjectList();
}
else
Expand Down
3 changes: 2 additions & 1 deletion libraries/src/Form/Field/EditorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ protected function getEditor()
->where('enabled = 1');

// Check of the editor exists.
$db->setQuery($query, 0, 1);
$query->setLimit(1);
$db->setQuery($query);
$editor = $db->loadResult();

// If an editor was found stop looking.
Expand Down
4 changes: 3 additions & 1 deletion libraries/src/Table/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ public function check()
->from($this->_db->quoteName($this->_tbl))
->where($this->_db->quoteName('id') . ' = ' . $this->parent_id);

if ($this->_db->setQuery($query, 0, 1)->loadResult())
$query->setLimit(1);

if ($this->_db->setQuery($query)->loadResult())
{
return true;
}
Expand Down
8 changes: 6 additions & 2 deletions libraries/src/Table/ContentHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ public function getHashMatch()
->where($db->quoteName('ucm_item_id') . ' = ' . (int) $this->get('ucm_item_id'))
->where($db->quoteName('ucm_type_id') . ' = ' . (int) $this->get('ucm_type_id'))
->where($db->quoteName('sha1_hash') . ' = ' . $db->quote($this->get('sha1_hash')));
$db->setQuery($query, 0, 1);

$query->setLimit(1);
$db->setQuery($query);

return $db->loadObject();
}
Expand All @@ -201,7 +203,9 @@ public function deleteOldVersions($maxVersions)
->where($db->quoteName('ucm_type_id') . ' = ' . (int) $this->get('ucm_type_id'))
->where($db->quoteName('keep_forever') . ' != 1')
->order($db->quoteName('save_date') . ' DESC ');
$db->setQuery($query, 0, (int) $maxVersions);

$query->setLimit((int) $maxVersions);
$db->setQuery($query);
$idsToSave = $db->loadColumn(0);

// Don't process delete query unless we have at least the maximum allowed versions
Expand Down
14 changes: 10 additions & 4 deletions libraries/src/Table/Nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ public function moveByReference($referenceId, $position = 'after', $pk = null, $
->from($this->_tbl)
->where('parent_id = 0')
->order('lft DESC');
$this->_db->setQuery($query, 0, 1);

$query->setLimit(1);
$this->_db->setQuery($query);
$reference = $this->_db->loadObject();

if ($this->_debug)
Expand Down Expand Up @@ -794,7 +796,9 @@ public function store($updateNulls = false)
->from($this->_tbl)
->where('parent_id = 0')
->order('lft DESC');
$this->_db->setQuery($query, 0, 1);

$query->setLimit(1);
$this->_db->setQuery($query);
$reference = $this->_db->loadObject();

if ($this->_debug)
Expand Down Expand Up @@ -1021,7 +1025,8 @@ public function publish($pks = null, $state = 1, $userId = 0)
->where($published . ' < ' . (int) $compareState);

// Just fetch one row (one is one too many).
$this->_db->setQuery($query, 0, 1);
$query->setLimit(1);
$this->_db->setQuery($query);

if ($this->_db->loadResult())
{
Expand Down Expand Up @@ -1637,7 +1642,8 @@ protected function _getNode($id, $key = null)
->from($this->_tbl)
->where($k . ' = ' . (int) $id);

$row = $this->_db->setQuery($query, 0, 1)->loadObject();
$query->setLimit(1);
$row = $this->_db->setQuery($query)->loadObject();

// Check for no $row returned
if (empty($row))
Expand Down
3 changes: 2 additions & 1 deletion libraries/src/Table/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,8 @@ public function move($delta, $where = '')
$this->getDispatcher()->dispatch('onTableBeforeMove', $event);

// Select the first row with the criteria.
$this->_db->setQuery($query, 0, 1);
$query->setLimit(1);
$this->_db->setQuery($query);
$row = $this->_db->loadObject();

// If a row is found, move the item.
Expand Down
4 changes: 2 additions & 2 deletions modules/mod_related_items/Helper/RelatedItemsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static function getList(&$params)
$app = Factory::getApplication();
$input = $app->input;
$groups = implode(',', Factory::getUser()->getAuthorisedViewLevels());
$maximum = (int) $params->get('maximum', 5);
$factory = $app->bootComponent('com_content')->getMVCFactory();

// Get an instance of the generic articles model
Expand Down Expand Up @@ -125,7 +124,8 @@ public static function getList(&$params)
$query->where('a.language in (' . $db->quote(Factory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
}

$db->setQuery($query, 0, $maximum);
$query->setLimit((int) $params->get('maximum', 5));
$db->setQuery($query);

try
{
Expand Down
4 changes: 2 additions & 2 deletions modules/mod_tags_similar/Helper/TagsSimilarHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public static function getList(&$params)
$user = Factory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$matchtype = $params->get('matchtype', 'all');
$maximum = $params->get('maximum', 5);
$ordering = $params->get('ordering', 'count');
$tagsHelper = new TagsHelper;
$prefix = $option . '.' . $view;
Expand Down Expand Up @@ -148,7 +147,8 @@ public static function getList(&$params)
$query->order($query->rand());
}

$db->setQuery($query, 0, $maximum);
$query->setLimit((int) $params->get('maximum', 5));
$db->setQuery($query);

try
{
Expand Down
3 changes: 2 additions & 1 deletion modules/mod_users_latest/Helper/UsersLatestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public static function getUsers($params)
->where($db->quoteName('ug.id') . ' <> 1');
}

$db->setQuery($query, 0, $params->get('shownumber', 5));
$query->setLimit((int) $params->get('shownumber', 5));
$db->setQuery($query);

try
{
Expand Down

0 comments on commit 803d2f2

Please sign in to comment.