I'm Currently using magento2.3, i have added a cron job to update products stock every 20 min from external inventory which will create a CSV file to magento directory, i will read this file and loop
to the quantity and create a SQL query to update it to cataloginventory_stock_item table and run reindex.
Quantity get updated but not showing add to cart in front-end , after product save manually from admin it's working fine. It is proper method to update qty or else there is any other method for performance using this method, because our store having more then 20K+ products
Best Answer
Please try the below code if it helps instead of updating the stock directly to the database table.
Use the
Magento\CatalogInventory\Api\StockRegistryInterface
to update the product qty.OR try the below sql query for update stock:
Hope this helps!