Smile-SA / mongogento

98 stars 48 forks source link

_loadAttributes() #26

Open yusrub opened 7 years ago

yusrub commented 7 years ago

Hi, I am working on this extension and found a function public function _loadAttributes($printQuery = false, $logQuery = false) in class Smile_MongoCatalog_Model_Resource_Override_Catalog_Product_Collection

`public function _loadAttributes($printQuery = false, $logQuery = false) { parent::_loadAttributes($printQuery, $logQuery);

    if (!empty($this->_itemsById)) {

        $storeFilter = array_unique(array('attr_' . $this->getDefaultStoreId(), 'attr_' . $this->getStoreId()));

        if (is_null($this->_loadedDocuments)) {

            $documentIds = $this->getLoadedIds();

            foreach ($documentIds as $key => $value) {
                $documentIds[$key] = (int)$value;
            }

my question is that did we need to call parent::_loadAttributes($printQuery, $logQuery); this function to load attributes from mysql as it return all attributes which is then useless to load the data in below code.

can we removed parent::_loadAttributes($printQuery, $logQuery); this part or thier is any logic/point .

can you explained

thanks in advanced

aftabnaveed commented 7 years ago

+1

southerncomputer commented 7 years ago

Because Attributes can come from both mysql and mongodb - you would want to load from both and merge otherwise you will not load all attributes! That is my understanding from using this extension!

yusrub commented 7 years ago

ok thanks for your reply

we are saving all attributes of product in mongo-db is am right? that why i am saying that we did not need to load attributes from mysql

southerncomputer commented 7 years ago

public function getSqlAttributesCodes() { if (is_null($this->_sqlAttributeCodes)) { $this->_sqlAttributeCodes = array(); $specialAttributes = array( 'visibility', 'status', 'price', 'tax_class_id', 'name', 'url_key', 'url_path', 'special_price', 'special_from_date', 'special_to_date', 'msrp', 'price_type' ); $staticFields = $this->_getWriteAdapter()->describeTable($this->getEntityTable()); $this->_sqlAttributeCodes = array_merge($specialAttributes, array_keys($staticFields)); } return $this->_sqlAttributeCodes; }

These Attributes are never stored in mongodb!

aftabnaveed commented 7 years ago

If we are still querying the the MYSQL for Attributes would it not kill purpose of using MongoDB? After all that's the whole purpose of using it and avoid querying EAV tables which in this case we are not, in fact it will slow down further, because we will be querying both EAV and now an additional request is sent to Mongo. The attributes you mentioned are already in Mongo.

yusrub commented 7 years ago

Hi Southerncomputer,

If you import data from mysql to mongo db using shell script, you will see all these attributes stored in mongo-db public function getSqlAttributesCodes() { if (is_null($this->_sqlAttributeCodes)) { $this->_sqlAttributeCodes = array(); $specialAttributes = array( 'visibility', 'status', 'price', 'tax_class_id', 'name', 'url_key', 'url_path', 'special_price', 'special_from_date', 'special_to_date', 'msrp', 'price_type' ); $staticFields = $this->_getWriteAdapter()->describeTable($this->getEntityTable()); $this->_sqlAttributeCodes = array_merge($specialAttributes, array_keys($staticFields)); } return $this->_sqlAttributeCodes; } will you checked and confirm

romainruaud commented 7 years ago

Hello everybody. @southerncomputer is right, there is some attributes that are kept into MySQL. These attributes are used when rebuilding Magento indexes, so we make them stay in MySQL to avoid having to rewrite all indexes processes. If you remove this data from MySQL, there won't be any index process running properly on your website, so the site may be broken.

Concerning the fact that we are loading these attributes from MySQL when loading a collection, I agree that it may does nothing.

Let's take a look at this : https://github.com/Smile-SA/mongogento/blob/master/src/app/code/community/Smile/MongoCatalog/Model/Resource/Override/Catalog/Product/Collection.php#L461

addAttributeToSelect is dismantled since we do not care about adding attributes to select one by one (we fetch a full mongo document everytime).

This would mean that when reaching this piece of code : http://doc4dev.net/doc/Magento/1/source-class-Mage_Eav_Model_Entity_Collection_Abstract.html#1076

The variable _selectAttributes should alway be empty : so we never build the query to load data from MySQL.

Feel free to test without the parent calls to _loadAttributes and let me know.

Regards

yusrub commented 7 years ago

I tested without the parent calls to _loadAttributes and it worked fined for me

southerncomputer commented 7 years ago

Perhaps it was legacy before the attribute migration tool that existed - so you could load attributes from mysql and save them to mongodb!

I remember that being the case before the migration tool existed you had to load each product from mysql and save() it to move the attributes to mongodb.