Do console commands use the memory_limit option in...
# help
r
Do console commands use the memory_limit option in deploy.yml? I'm trying to update a category and it crashes
Copy code
docker/sdk console kesko:disable-empty-categories                                                                                                                                                                                                                                                                                                                                                            in nu at 09:11:19
-->  DEVELOPMENT MODE   
Store: FI | Environment: docker.local
[31-May-2023 06:11:45 UTC] PHP Fatal error:  Allowed memory size of 2147483648 bytes exhausted (tried to allocate 20480 bytes) in /data/src/Orm/Zed/Category/Persistence/Base/SpyCategory.php on line 1613

Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 20480 bytes) in /data/src/Orm/Zed/Category/Persistence/Base/SpyCategory.php on line 1613
[31-May-2023 06:11:45 UTC] PHP Fatal error:  Allowed memory size of 2147483648 bytes exhausted (tried to allocate 65536 bytes) in /data/vendor/composer/ClassLoader.php on line 571

Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 65536 bytes) in /data/vendor/composer/ClassLoader.php on line 571
p
yes, they should, make sure to bootstrap the deploy file again after making a change
r
so it still goes over 🤔
p
according to the error message you have currently 2048MB configured?
r
yes
p
More than 2GB you should generally not configure. Is it possible to do what you are trying to do in batches maybe?
r
certainly if I knew how 😄
Copy code
$categoryIds // Long list of category ids...
        foreach ($categoryIds as $categoryId) {
            $category = $this->getFactory()->getCategoryFacade()->findCategoryById($categoryId);
            $category->setIsActive(false);
            $this->getFactory()->getCategoryFacade()->update($category);
        }
from my end its not even batching but doing it one by one
b
I think there is some internal caching in propel (and also for example storage clients, if you use it somewhere) which can lead to huge memory consumptions even if it seems that it should not
w
Propel::_disableInstancePooling_();
1
🎉 1
But it can also be due to recursive category updates that happen when you update one of the top categories in a complex and deep category tree
r
oh wow not only helped the operation turned instantaneous
now to figure out a clean way to do that since all the propel code is inside spryker/category module 😄
b
I think it would be cleaner to write your own query to disable categories by a list of category ids, since category.is_active is probably only a boolen / 1/0 db field?
then you can do it in one update query instead of iterating
r
well I would like to rely on the category module that it does all the publishing properly
b
sure, I was thinking about the data import, it triggers the publish events anyway, but of course you would have to add the logic which is already present on the category facade
r
and theres that closure table that looks like black magic
😄 1
b
ok, I think you convinced me
r
I'm trying to disable all categories that are empty
i.e. no products in them
of course if there's a better way I'm all ears 🙂
w
Closure table's aren't black magic by any mean, they are a well documented concept to store trees in flat DB tables. Spryker did the closure implementation, as well as anything else for the categories, in PHP, while most part's would have been a lot more efficient to implement directly in SQL. An example, during publishing of a product the whole category tree is loaded in memory, only to find all parent category ids of the categories the product is attached to. This is a one liner with SQL in a closure table implementation (
SELECT fk_category_node FROM spy_category_closure_table WHERE fk_category_node_descendant = :categoryNodeId
)
👀 1
r
Yeah thanks, I'm somewhat familiar with the concept, I meant more that there's a lot of code that get's executed when you do categoryfacade()->update($category). I could probably utilize that table to find the empty categories 🤔 I just now wrote a recursive SQL query