Skip to content

Commit e193cf5

Browse files
MAGETWO-70066: Significant degradation of Catalog Permissions indexer with big number of customer groups
1 parent 13ed494 commit e193cf5

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ public function insertMultiple($table, array $data);
464464
* array('value1', 'value2')
465465
*
466466
* @param string $table
467-
* @param array $columns the data array column map
467+
* @param string[] $columns the data array column map
468468
* @param array $data
469469
* @return int
470470
*/

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,12 +1973,13 @@ public function insertMultiple($table, array $data)
19731973
* array('value1', 'value2')
19741974
*
19751975
* @param string $table
1976-
* @param array $columns
1976+
* @param string[] $columns
19771977
* @param array $data
1978-
* @return int
1979-
* @throws \Zend_Db_Exception
1978+
* @param int $strategy
1979+
* @return int
1980+
* @throws \Zend_Db_Exception
19801981
*/
1981-
public function insertArray($table, array $columns, array $data)
1982+
public function insertArray($table, array $columns, array $data, $strategy = 0)
19821983
{
19831984
$values = [];
19841985
$bind = [];
@@ -1990,10 +1991,16 @@ public function insertArray($table, array $columns, array $data)
19901991
$values[] = $this->_prepareInsertData($row, $bind);
19911992
}
19921993

1993-
$insertQuery = $this->_getInsertSqlQuery($table, $columns, $values);
1994+
switch ($strategy) {
1995+
case self::INSERT_ON_DUPLICATE:
1996+
$query = $this->_getReplaceSqlQuery($table, $columns, $values);
1997+
break;
1998+
default:
1999+
$query = $this->_getInsertSqlQuery($table, $columns, $values);
2000+
}
19942001

19952002
// execute the statement and return the number of affected rows
1996-
$stmt = $this->query($insertQuery, $bind);
2003+
$stmt = $this->query($query, $bind);
19972004
$result = $stmt->rowCount();
19982005

19992006
return $result;
@@ -3635,6 +3642,26 @@ protected function _getInsertSqlQuery($tableName, array $columns, array $values)
36353642
return $insertSql;
36363643
}
36373644

3645+
/**
3646+
* Return replace sql query
3647+
*
3648+
* @param string $tableName
3649+
* @param array $columns
3650+
* @param array $values
3651+
* @return string
3652+
*/
3653+
protected function _getReplaceSqlQuery($tableName, array $columns, array $values)
3654+
{
3655+
$tableName = $this->quoteIdentifier($tableName, true);
3656+
$columns = array_map([$this, 'quoteIdentifier'], $columns);
3657+
$columns = implode(',', $columns);
3658+
$values = implode(', ', $values);
3659+
3660+
$replaceSql = sprintf('REPLACE INTO %s (%s) VALUES %s', $tableName, $columns, $values);
3661+
3662+
return $replaceSql;
3663+
}
3664+
36383665
/**
36393666
* Return ddl type
36403667
*

0 commit comments

Comments
 (0)