You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please provide starting context, i.e. logged in as a user, configure a particular payment method.
Create a store
Import over a million products
Without tuning the node vm, RC will OOM and crash
Possible Solution
Include a flag to build inventory as a background job instead of inside of "afterCoreInit". The job should pluck id's by the 1000's or 10 of 1000's and perform bulk updates of the inventory collection to be performant.
import { Hooks, Logger } from "/server/api";
import { Products, Inventory } from "/lib/collections";
import { registerInventory } from "../methods/inventory";
// On first-time startup init the Inventory collection with entries for each product
Hooks.Events.add("afterCoreInit", () => {
// If we already have any inventory record, skip
const inventory = Inventory.find().count();
if (!inventory) {
const products = Products.find().fetch();
for (const product of products) {
Logger.debug(`Registering product ${product.title}`);
registerInventory(product);
}
}
});
In the above code, the dangerous method is Products.find().count(), for most e-commerce stores, this wont cause an issue, for those with millions of Products this code isn't suitable. Perhaps a flag to turn this off is a good idea. A larger deployment will likely need a custom means of managing inventory
The text was updated successfully, but these errors were encountered:
Steps to Reproduce
Please provide starting context, i.e. logged in as a user, configure a particular payment method.
Possible Solution
Include a flag to build inventory as a background job instead of inside of "afterCoreInit". The job should pluck id's by the 1000's or 10 of 1000's and perform bulk updates of the inventory collection to be performant.
In the above code, the dangerous method is Products.find().count(), for most e-commerce stores, this wont cause an issue, for those with millions of Products this code isn't suitable. Perhaps a flag to turn this off is a good idea. A larger deployment will likely need a custom means of managing inventory
The text was updated successfully, but these errors were encountered: