Skip to content

Commit

Permalink
Merge pull request PAYONE-GmbH#269 from BoulangerV/OX6-147-Perfomance…
Browse files Browse the repository at this point in the history
…_Optimierung

OX6-147: Apply DB optimization (indexes)
  • Loading branch information
janteuber authored May 9, 2023
2 parents b7522b7 + e33d198 commit 29cae55
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions core/fcpayone_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ class fcpayone_events
public static $sQueryFcpotransactionstatusCopyTimestampData = "UPDATE fcpotransactionstatus SET OXTIMESTAMP = FCPO_TIMESTAMP;";
public static $sQueryFcpocheckedaddressesCopyTimestampData = "UPDATE fcpocheckedaddresses SET OXTIMESTAMP = fcpo_checkdate;";
public static $sQueryAlterFcpoShadowBasketFcbasketChangeToLongText = "ALTER TABLE fcposhadowbasket MODIFY FCPOBASKET LONGTEXT;";
public static $sQueryAlterOxorderTxidIndex = "ALTER TABLE oxorder ADD INDEX FCPOTXID (`FCPOTXID`)";
public static $sQueryAlterFcpotransactionstatusTxidIndex = "ALTER TABLE fcpotransactionstatus ADD INDEX FCPO_TXID (`FCPO_TXID`)";
public static $sQueryAlterFcpotransactionstatusTxactionIndex = "ALTER TABLE fcpotransactionstatus ADD INDEX FCPO_TXACTION (`FCPO_TXACTION`)";
public static $sQueryAlterFcpotransactionstatusSequencenumberIndex = "ALTER TABLE fcpotransactionstatus ADD INDEX FCPO_SEQUENCENUMBER (`FCPO_SEQUENCENUMBER`)";
public static $sQueryAlterFcporequestlogRefnrIndex = "ALTER TABLE fcporequestlog ADD INDEX FCPO_REFNR (`FCPO_REFNR`)";
public static $sQueryAlterFcporequestlogRequesttypeIndex = "ALTER TABLE fcporequestlog ADD INDEX FCPO_REQUESTTYPE (`FCPO_REQUESTTYPE`)";

public static $aPaymentMethods = array(
'fcpoinvoice' => 'PAYONE Rechnungskauf',
Expand Down Expand Up @@ -670,6 +676,14 @@ public static function addDatabaseStructure()

// OX6-127: CHANGE SHADOW BASKET TYPE
self::changeColumnTypeIfWrong('fcposhadowbasket', 'FCPOBASKET', 'LONGTEXT', self::$sQueryAlterFcpoShadowBasketFcbasketChangeToLongText);

// OX6-147: ADD PERFORMANCE INDEXES
self::addIndexIfNotExists('oxorder', 'FCPOTXID', self::$sQueryAlterOxorderTxidIndex);
self::addIndexIfNotExists('fcpotransactionstatus', 'FCPO_TXID', self::$sQueryAlterFcpotransactionstatusTxidIndex);
self::addIndexIfNotExists('fcpotransactionstatus', 'FCPO_TXACTION', self::$sQueryAlterFcpotransactionstatusTxactionIndex);
self::addIndexIfNotExists('fcpotransactionstatus', 'FCPO_SEQUENCENUMBER', self::$sQueryAlterFcpotransactionstatusSequencenumberIndex);
self::addIndexIfNotExists('fcporequestlog', 'FCPO_REFNR', self::$sQueryAlterFcporequestlogRefnrIndex);
self::addIndexIfNotExists('fcporequestlog', 'FCPO_REQUESTTYPE', self::$sQueryAlterFcporequestlogRequesttypeIndex);
}

/**
Expand Down Expand Up @@ -804,6 +818,26 @@ public static function changeColumnNameIfWrong($sTableName, $sColumnName, $sQuer
return false;
}

/**
* Add a database index.
*
* @param string $sTable database table name
* @param string $sIndex database index name
* @param string $sQuery sql-query to execute
*
* @return boolean true or false
*/
public static function addIndexIfNotExists($sTable, $sIndex, $sQuery)
{
$sExisting = oxDb::getDb()->getOne("SHOW KEYS FROM {$sTable} WHERE Key_name = '{$sIndex}'");
if (!$sExisting) {
oxDb::getDb()->Execute($sQuery);
return true;
}

return false;
}

/**
* Delete a database index.
*
Expand Down

0 comments on commit 29cae55

Please sign in to comment.