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

/imports/included/inventory/server/init.js Not suitable for large stores. #4215

Closed
dhonig opened this issue Apr 26, 2018 · 1 comment
Closed
Assignees
Labels
bug For issues that describe a defect or regression in the released software

Comments

@dhonig
Copy link
Collaborator

dhonig commented Apr 26, 2018

Steps to Reproduce

Please provide starting context, i.e. logged in as a user, configure a particular payment method.

  1. Create a store
  2. Import over a million products
  3. 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

@brent-hoover brent-hoover added bug For issues that describe a defect or regression in the released software impact-minor labels May 1, 2018
@brent-hoover
Copy link
Collaborator

Flagging this minor since the workaround is to just remove the inventory plugin and use your own which can be done without any modifications to core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For issues that describe a defect or regression in the released software
Projects
None yet
Development

No branches or pull requests

3 participants