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

Importer will get slow and memory issue if large number of products imported #224

Open
gomcodoctor opened this issue Feb 1, 2020 · 1 comment

Comments

@gomcodoctor
Copy link

product importer is prone to memory issue if entities are not cleared regularly.
for CLASSNAMES - we can add a method call on service to add list of all classes to clear.

Suggestion and feedback appreciated

$this->objectManager->flush();

should be replaced to

$this->objectManager->flush();

            foreach(CLASSNAMES  as CLASSNAME) 
                $this->objectManager->clear(CLASSNAME)

public function importData(int $i, array $row): bool
    {
        try {
            $this->resourceProcessor->process($row);
            $this->result->success($i);

            ++$this->batchCount;
            if ($this->batchSize && $this->batchCount === $this->batchSize) {
                $this->objectManager->flush();
                $this->batchCount = 0;
            }
        } catch (ItemIncompleteException $e) {
            $this->result->setMessage($e->getMessage());
            $this->result->getLogger()->critical($e->getMessage());
            if ($this->failOnIncomplete) {
                $this->result->failed($i);
                if ($this->stopOnFailure) {
                    return true;
                }
            } else {
                $this->result->skipped($i);
            }
        } catch (ImporterException $e) {
            $this->result->failed($i);
            $this->result->setMessage($e->getMessage());
            $this->result->getLogger()->critical($e->getMessage());
            if ($this->stopOnFailure) {
                return true;
            }
        }

        return false;
    }

@oallain
Copy link
Member

oallain commented Feb 18, 2020

Hi @gomcodoctor

Yes, we can do that 😄
Do you want to propose PR ?

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

No branches or pull requests

2 participants