admin管理员组

文章数量:1402955

The iOS production app, built from Expo Go, successfully downloaded a large amount of data (over 40,000 products). However, when trying to select data from these items, the app crashes. How can this issue be fixed?
This is insert 40000 products and over 100 stock locations from odoo in function ProductList()

async function getProductListDownload() {
    try {
      const result = await odoo.call('get_product_list_mobile', {
        model: 'product.product',
        args: ['product.product'],
      });
  
      if (result) {
        for (const product of result) {
          
          await insertProductList({
            id: product.id,
            name:product.name,
            default_code: product.default_code,
            barcode: product.barcode,
            standard_price: product.standard_price || 0,
            lst_price: product.lst_price || 0,           
            uom_id: product.uom_id,
            product_tmpl_id: product.product_tmpl_id,
            write_date: product.write_date,
            tracking: product.tracking,
            type: product.type,
            categ_id: product.categ_id,
            brand_name: product.brand_name,
            taxes_id: product.taxes_id || [],
          });
        }
        
  
        console.log('All products inserted successfully.');
      } else {
        console.error('Failed to fetch product list:', result);
      }
    } catch (error) {
      console.error('Error in getProductListDownload:', error);
    }
  }
async function getWarehouseOfUser() {
    try {
      const result = await odoo.read({
        model: "res.users",
        id: userId,
        fields: ["allowed_warehouse_ids"],
        context:{
          allowed_company_ids:[
            odoopany_id
          ]
        }
      });
  
      const allowedWarehouseIds = result[0]?.allowed_warehouse_ids || [];
  
      if (allowedWarehouseIds.length > 0) {
        for (const warehouseId of allowedWarehouseIds) {
          try {
            const warehouse = await odoo.read({
              model: "stock.warehouse",
              id: warehouseId,
              fields: ["id", "name", "lot_stock_id", "company_id"],
            });

            const warehouseData = Array.isArray(warehouse) ? warehouse[0] : warehouse;
            if (warehouseData) {
              const lotStockId = warehouseData.lot_stock_id?.[0] || null;
              const lotStockName = warehouseData.lot_stock_id?.[1] || "";
              const companyId = warehouseDatapany_id?.[0] || null;
              const companyName = warehouseDatapany_id?.[1] || "";
  
              await insertStockWarehouseList({
                id: warehouseData.id,
                name: warehouseData.name,
                lot_stock_id: lotStockId,
                company_id: companyId
              });
  
              if (lotStockId && lotStockName) {
                await insertStockLocationList({
                  id: lotStockId,
                  name: lotStockName,
                  company_id: companyId
                });
                console.log(`Location ${lotStockId} inserted successfully.`);
              } else {
                console.log(`Skipping insertion for warehouse ${warehouseId}: Missing lot_stock_id or lot_stock_name.`);
              }
            }
          } catch (error) {
            console.error(`Failed to fetch warehouse ID: ${warehouseId}`, error);
          }
        }
      } else {
        console.log("No allowed warehouses found.");
      }
    } catch (error) {
      console.log("Error in getWarehouseOfUser:", error);
    }
  }  

This is InventoryForm() function's inventory counting code

const getProductData = async (limit = 100) => {
  try {
    const db = await SQLite.openDatabaseAsync('oderp.db');
    const result = await db.getAllAsync(`SELECT * FROM product_product LIMIT ?`, [limit]);
    return result;
  } catch (e) {
    console.error('Error fetching product data:', e);
    return [];
  }
};

const searchProduct = async (query) => {
  try {
    const db = await SQLite.openDatabaseAsync('oderp.db');
    const result = await db.getAllAsync(
      `SELECT * FROM product_product WHERE name LIKE ? OR default_code LIKE ? LIMIT 50`,
      [`%${query}%`, `%${query}%`]
    );
    return result;
  } catch (e) {
    console.error('Error searching product:', e);
    return [];
  }
};

const getLocationData = async () => {
  try {
    const db = await SQLite.openDatabaseAsync('oderp.db');
    const result = await db.getAllAsync('SELECT id, name FROM stock_location');
    return result;
  } catch (e) {
    console.error('Error fetching location data:', e);
    return [];
  }
};

const searchLocation = async (query) => {
  try {
    const db = await SQLite.openDatabaseAsync('oderp.db');
    const result = await db.getAllAsync(
      `SELECT * FROM stock_location WHERE name LIKE ? LIMIT 50`,
      [`%${query}%`]
    );
    return result;
  } catch (e) {
    console.error('Error searching location:', e);
    return [];
  }
};
  useEffect(() => {
    const fetchProductData = async () => {
      const products = await getProductData();
      console.log("--------fetch product-----")
      setProductOptions(products);
    };
    
    fetchProductData();
  }, []);

  useEffect(() => {
    const fetchLocationData = async () => {
      const locations = await getLocationData();
      console.log("------locations----", locations)
      setLocationOptions(locations);
    };
    
    fetchLocationData();
  }, []);

The app on TestFlight initially downloads 40,000 items. After that, when navigating to the inventory counting screen and performing select or search operations on the downloaded 40,000 items, the screen freezes and then crashes.
In the Expo Go development environment, it works normally.
Please, help me :)

本文标签: react nativeHow to fix crash ios production from expo goStack Overflow