What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

About

UM4BZSK7T
UM4BZSK7T Posts: 174 🧑🏻‍🚀 - Cadet

About https://github.com/spryker/company-role/blob/1.7.1/src/Spryker/Zed/CompanyRole/Persistence/Mapper/CompanyRoleCompanyUserMapper.php We have companies with many users. https://blackfire.io/profiles/d30d8669-c9fe-4e77-95d8-259f2b1dfc7a/graph As you can see in this case the hydration is called 48 times and we had around 100 test users. This resulted in three 2 x 4944 calls to fromArray() and toArray() as this transferObject ins converted. And 4944 other things that didn't have so much impact. And after that the whole data is loaded in the session and bloats the session beyond reasonable usage. So we decided to just do not load this Collection inside of Zed\CompanyRole\Persistence\CompanyRoleRepository::prepareCompanyRoleTransfer . We did this by inheritance which leaves a bad feeling if there are changes in any later version of spryker. By composition is not an option. Or we could rewrite a lot code paths in the system. So just load the User Collection on demand seemed to be the best option. Any ideas how this could be solved better? My best guess is that the core behaviour should be changed here. But maybe there is even a better solution we didn't guess?

Comments

  • Valerii Trots
    Valerii Trots SRE @ Spryker Sprykee Posts: 1,654 ✨ - Novice

    Hi Karsten, I believe we have some improvements requests from the related area already but still it would help if you could create a support request so we could forward it to our development team for fixing if it's not the same or push them if such a request already exists.

  • giovanni.piemontese
    giovanni.piemontese Spryker Solution Partner Posts: 871 🧑🏻‍🚀 - Cadet

    We had the same problem... already pushed to spryker... (July 2020).

    We have with Spryker Dev last year investigated and we found out that the has no sense the company user hydration there..

    We have too overrided it on pyz level so:

        /**
         * @param \Orm\Zed\CompanyRole\Persistence\SpyCompanyRole $spyCompanyRole
         *
         * @return \Generated\Shared\Transfer\CompanyRoleTransfer
         */
        protected function prepareCompanyRoleTransfer(SpyCompanyRole $spyCompanyRole): CompanyRoleTransfer
        {
            $companyRoleTransfer = $this->getFactory()
                ->createCompanyRoleMapper()
                ->mapEntityToCompanyRoleTransfer(
                    $spyCompanyRole,
                    new CompanyRoleTransfer()
                );
    
            $companyRoleTransfer = $this->getFactory()
                ->createCompanyRolePermissionMapper()
                ->hydratePermissionCollection(
                    $spyCompanyRole,
                    $companyRoleTransfer
                );
    
            $companyRoleTransfer = $this->getFactory()
                ->createCompanyRoleCompanyMapper()
                ->mapCompanyFromCompanyRoleEntityToCompanyRoleTransfer(
                    $spyCompanyRole,
                    $companyRoleTransfer
                );
    
            return $companyRoleTransfer;
        }
    

    And everything works fine.

  • UKTSRTD5M
    UKTSRTD5M Posts: 77 🧑🏻‍🚀 - Cadet

    Thanks @UL65CH0MC for sharing - that's somehow what we are doing as well.

  • UM4BZSK7T
    UM4BZSK7T Posts: 174 🧑🏻‍🚀 - Cadet

    @valerii.trots i used your form and created a case

  • Valerii Trots
    Valerii Trots SRE @ Spryker Sprykee Posts: 1,654 ✨ - Novice

    We've got it, thanks! 🙂