Skip to content

Commit

Permalink
Added configuration for maximum number of records for aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed May 12, 2021
1 parent 3639fdb commit e1de37d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/mshoplib/src/MShop/Common/Manager/Base.php
Expand Up @@ -237,6 +237,22 @@ protected function addSqlColumns( array $columns, string $sql, bool $mode = true
protected function aggregateBase( \Aimeos\MW\Criteria\Iface $search, $keys, string $cfgPath,
array $required = [], string $value = null, string $type = null ) : \Aimeos\Map
{
/** mshop/common/manager/aggregate/limit
* Limits the number of records that are used when aggregating items
*
* As counting huge amount of records (several 10 000 records) takes a long time,
* the limit can cut down response times so the counts are available more quickly
* in the front-end and the server load is reduced.
*
* Using a low limit can lead to incorrect numbers if the amount of found items
* is very high. Approximate item counts are normally not a problem but it can
* lead to the situation that visitors see that no items are available despite
* the fact that there would be at least one.
*
* @param integer Number of records
* @since 2021.04
*/
$limit = $this->context->getConfig()->get( 'mshop/common/manager/aggregate/limit', 10000 );
$keys = (array) $keys;

if( !count( $keys ) ) {
Expand All @@ -252,6 +268,7 @@ protected function aggregateBase( \Aimeos\MW\Criteria\Iface $search, $keys, stri
$total = null;
$cols = $map = [];
$search = clone $search;
$search->slice( $search->getOffset(), min( $search->getLimit(), $limit ) );

$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
$attrList = $this->getObject()->getSearchAttributes();
Expand Down
2 changes: 1 addition & 1 deletion lib/mshoplib/src/MShop/Index/Manager/Standard.php
Expand Up @@ -306,7 +306,7 @@ public function rebuild( iterable $items = [] ) : \Aimeos\MShop\Index\Manager\If
$search->setConditions( $search->compare( '==', 'product.id', $result->keys()->toArray() ) );
$this->writeIndex( $search, $domains, $size );

$start += $size;
$start += count( $result );
}
while( !$result->isEmpty() );

Expand Down

0 comments on commit e1de37d

Please sign in to comment.