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

Add cluster/multiprocess support #3

Open
pkarw opened this issue Dec 31, 2017 · 0 comments
Open

Add cluster/multiprocess support #3

pkarw opened this issue Dec 31, 2017 · 0 comments

Comments

@pkarw
Copy link
Contributor

pkarw commented Dec 31, 2017

We need to modify the attribute.mapToVS to work on global/shared attributes hash

Attribute values are populated by each process/product import - so if the state weren't shared it would have been easily desynchronized. Right now because we don't support multiprocess it's pretty straightforward: using a local hash.

Here is the function to be modified with some notes on the possible solutions:
\

function mapToVS (attributeCode, attributeType, attributeValue) {
    let attr = attrHash[attributeCode]
    if (! attr) {
        attr = attributeTemplate(attributeCode, attributeType)
        attr.id = maxAttrId
        attr.attribute_id = maxAttrId
        
        attrHash[attributeCode] = attr
        maxAttrId++
    } 
    if (attr.frontend_input == 'select') {
        let existingOption = attr.options.find((option) => { return option.label == attributeValue})
        if(!existingOption) {
            let lastOption = attr.options.length > 0 ? attr.options[attr.options.length-1] : null // we can use memored or elastic search to store each option per each attribute separately - to keep the same indexes between processes for example key would be: $attribute_code$$attribute_value = 14 
                                                                                                  // OR SEND MODIFIED attributes to the workers each time attrHash changes: https://nodejs.org/api/cluster.html#cluster_cluster_workers
            let optIndex = 1
            if (lastOption) {
                optIndex = lastOption.value + 1
            }
            attr.options.push({
                label: attributeValue,
                value: optIndex
            })
            return optIndex
        } else {
            return existingOption.value // non select attrs
        }


    } else {
        return attributeValue
        // we're fine here for decimal and varchar attributes
    }
}
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

1 participant