Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_loadAttributes() #26

Open
yusrub opened this issue Jul 14, 2016 · 9 comments
Open

_loadAttributes() #26

yusrub opened this issue Jul 14, 2016 · 9 comments

Comments

@yusrub
Copy link

yusrub commented Jul 14, 2016

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
Copy link

+1

@southerncomputer
Copy link

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
Copy link
Author

yusrub commented Jul 19, 2016

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
Copy link

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
Copy link

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
Copy link
Author

yusrub commented Jul 20, 2016

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
Copy link
Contributor

romainruaud commented Jul 20, 2016

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
Copy link
Author

yusrub commented Jul 21, 2016

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

@southerncomputer
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants