Skip to content

Commit c450d45

Browse files
Reduce needless saves by avoiding setting _hasDataChanges flag (#2066)
1 parent f93c9e0 commit c450d45

File tree

13 files changed

+72
-16
lines changed

13 files changed

+72
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Do not use 20.x.x if you need IE support.
8686
- fixed incorrect datetime in customer block (`$useTimezone` parameter) #1525
8787
- add redis as a valid option for `global/session_save` #1513
8888
- possibility to disable global search in backend #1532
89+
- reduce needless saves by avoiding setting `_hasDataChanges` flag #2066
8990

9091
For full list of changes, you can [compare tags](https://github.com/OpenMage/magento-lts/compare/1.9.4.x...20.0).
9192

app/code/core/Mage/Catalog/Model/Product.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,6 @@
223223
* @method $this setStoreId(int $store)
224224
* @method bool hasStoreIds()
225225
* @method $this setStoreIds(array $storeIds)
226-
* @method Mage_CatalogInventory_Model_Stock_Item getStockItem()
227-
* @method bool hasStockItem()
228-
* @method $this setStockItem(Mage_CatalogInventory_Model_Stock_Item $value)
229226
* @method array getSwatchPrices()
230227
*
231228
* @method int getTaxClassId()
@@ -344,6 +341,11 @@ class Mage_Catalog_Model_Product extends Mage_Catalog_Model_Abstract
344341
*/
345342
protected $_calculatePrice = true;
346343

344+
/**
345+
* @var Mage_CatalogInventory_Model_Stock_Item
346+
*/
347+
protected $_stockItem;
348+
347349
/**
348350
* Initialize resources
349351
*/
@@ -694,6 +696,32 @@ public function getAttributes($groupId = null, $skipSuper = false)
694696
return $attributes;
695697
}
696698

699+
/**
700+
* @return Mage_CatalogInventory_Model_Stock_Item
701+
*/
702+
public function getStockItem()
703+
{
704+
return $this->_stockItem;
705+
}
706+
707+
/**
708+
* @return bool
709+
*/
710+
public function hasStockItem()
711+
{
712+
return !!$this->_stockItem;
713+
}
714+
715+
/**
716+
* @param Mage_CatalogInventory_Model_Stock_Item $stockItem
717+
* @return $this
718+
*/
719+
public function setStockItem(Mage_CatalogInventory_Model_Stock_Item $stockItem)
720+
{
721+
$this->_stockItem = $stockItem;
722+
return $this;
723+
}
724+
697725
/**
698726
* Check product options and type options and save them, too
699727
*

app/code/core/Mage/Customer/Model/Address.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ public function getCustomer()
9797
public function setCustomer(Mage_Customer_Model_Customer $customer)
9898
{
9999
$this->_customer = $customer;
100-
$this->setCustomerId($customer->getId());
100+
if ($this->getCustomerId() != $customer->getId()) {
101+
$this->setCustomerId($customer->getId());
102+
}
101103
return $this;
102104
}
103105

app/code/core/Mage/Sales/Model/Order/Creditmemo/Item.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ public function getCreditmemo()
176176
public function setOrderItem(Mage_Sales_Model_Order_Item $item)
177177
{
178178
$this->_orderItem = $item;
179-
$this->setOrderItemId($item->getId());
179+
if ($this->getOrderItemId() != $item->getId()) {
180+
$this->setOrderItemId($item->getId());
181+
}
180182
return $this;
181183
}
182184

app/code/core/Mage/Sales/Model/Order/Invoice/Item.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ public function getInvoice()
159159
public function setOrderItem(Mage_Sales_Model_Order_Item $item)
160160
{
161161
$this->_orderItem = $item;
162-
$this->setOrderItemId($item->getId());
162+
if ($this->getOrderItemId() != $item->getId()) {
163+
$this->setOrderItemId($item->getId());
164+
}
163165
return $this;
164166
}
165167

app/code/core/Mage/Sales/Model/Order/Item.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,9 @@ public function getQtyToCancelBundleItem()
440440
public function setOrder(Mage_Sales_Model_Order $order)
441441
{
442442
$this->_order = $order;
443-
$this->setOrderId($order->getId());
443+
if ($this->getOrderId() != $order->getId()) {
444+
$this->setOrderId($order->getId());
445+
}
444446
return $this;
445447
}
446448

app/code/core/Mage/Sales/Model/Order/Shipment/Item.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public function getShipment()
104104
public function setOrderItem(Mage_Sales_Model_Order_Item $item)
105105
{
106106
$this->_orderItem = $item;
107-
$this->setOrderItemId($item->getId());
107+
if ($this->getOrderItemId() != $item->getId()) {
108+
$this->setOrderItemId($item->getId());
109+
}
108110
return $this;
109111
}
110112

app/code/core/Mage/Sales/Model/Quote.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ public function getStore()
297297
*/
298298
public function setStore(Mage_Core_Model_Store $store)
299299
{
300-
$this->setStoreId($store->getId());
300+
if ($this->getStoreId() != $store->getId()) {
301+
$this->setStoreId($store->getId());
302+
}
301303
return $this;
302304
}
303305

app/code/core/Mage/Sales/Model/Quote/Address.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,9 @@ protected function _afterSave()
427427
public function setQuote(Mage_Sales_Model_Quote $quote)
428428
{
429429
$this->_quote = $quote;
430-
$this->setQuoteId($quote->getId());
430+
if ($this->getQuoteId() != $quote->getId()) {
431+
$this->setQuoteId($quote->getId());
432+
}
431433
return $this;
432434
}
433435

app/code/core/Mage/Sales/Model/Quote/Item.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ protected function _beforeSave()
275275
public function setQuote(Mage_Sales_Model_Quote $quote)
276276
{
277277
$this->_quote = $quote;
278-
$this->setQuoteId($quote->getId());
278+
if ($this->getQuoteId() != $quote->getId()) {
279+
$this->setQuoteId($quote->getId());
280+
}
279281
return $this;
280282
}
281283

app/code/core/Mage/Sales/Model/Quote/Item/Option.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ protected function _hasModelChanged()
8383
*/
8484
public function setItem($item)
8585
{
86-
$this->setItemId($item->getId());
8786
$this->_item = $item;
87+
if ($this->getItemId() != $item->getId()) {
88+
$this->setItemId($item->getId());
89+
}
8890
return $this;
8991
}
9092

@@ -106,8 +108,10 @@ public function getItem()
106108
*/
107109
public function setProduct($product)
108110
{
109-
$this->setProductId($product->getId());
110111
$this->_product = $product;
112+
if ($this->getProductId() != $product->getId()) {
113+
$this->setProductId($product->getId());
114+
}
111115
return $this;
112116
}
113117

app/code/core/Mage/Sales/Model/Quote/Payment.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ protected function _construct()
119119
public function setQuote(Mage_Sales_Model_Quote $quote)
120120
{
121121
$this->_quote = $quote;
122-
$this->setQuoteId($quote->getId());
122+
if ($this->getQuoteId() != $quote->getId()) {
123+
$this->setQuoteId($quote->getId());
124+
}
123125
return $this;
124126
}
125127

app/code/core/Mage/Wishlist/Model/Item/Option.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* @method int getProductId()
3737
* @method $this setProductId(int $value)
3838
* @method $this setWishlistItemId(int $value)
39+
* @method int getWishlistItemId()
3940
* @method $this setValue(string $sBuyRequest)
4041
*/
4142
class Mage_Wishlist_Model_Item_Option extends Mage_Core_Model_Abstract implements Mage_Catalog_Model_Product_Configuration_Item_Option_Interface
@@ -73,8 +74,10 @@ protected function _hasModelChanged()
7374
*/
7475
public function setItem($item)
7576
{
76-
$this->setWishlistItemId($item->getId());
7777
$this->_item = $item;
78+
if ($this->getWishlistItemId() != $item->getId()) {
79+
$this->setWishlistItemId($item->getId());
80+
}
7881
return $this;
7982
}
8083

@@ -96,8 +99,10 @@ public function getItem()
9699
*/
97100
public function setProduct($product)
98101
{
99-
$this->setProductId($product->getId());
100102
$this->_product = $product;
103+
if ($this->getProductId() != $product->getId()) {
104+
$this->setProductId($product->getId());
105+
}
101106
return $this;
102107
}
103108

0 commit comments

Comments
 (0)