Skip to content

Instantly share code, notes, and snippets.

@grindtildeath
Created September 30, 2022 08:34
Show Gist options
  • Save grindtildeath/39d04273fa1c515be6235c846a0d4ffa to your computer and use it in GitHub Desktop.
Save grindtildeath/39d04273fa1c515be6235c846a0d4ffa to your computer and use it in GitHub Desktop.
Profile _search_product_qty v14.0 on 33031 records
2022-09-30 08:27:32,167 1 INFO zhinst_lab odoo.tools.profiler:
calls queries ms
stock.production.lot --------------------- /odoo/external-src/stock-logistics-workflow/stock_lot_product_qty_search/models/stock_production_lot.py, 17
1 0 0.05 @profile
def _search_product_qty(self, operator, value):
1 0 0.04 if operator not in ("<", ">", "=", "!=", "<=", ">="):
raise UserError(_("Invalid domain operator %s", operator))
1 0 0.03 if not isinstance(value, (float, int)):
raise UserError(_("Invalid domain right operand %s", value))
1 0 0.02 locations_domain = OR(
[
1 0 0.02 [("usage", "=", "internal")],
1 0 0.15 [("usage", "=", "transit"), ("company_id", "!=", False)],
]
)
1 7 31.91 quants_locations = self.env["stock.location"].search(locations_domain)
1 0 0.06 grouped_quants = self.env["stock.quant"].read_group(
1 0 0.09 [("lot_id", "!=", False), ("location_id", "in", quants_locations.ids)],
1 0 0.01 ["lot_id", "quantity"],
1 0 0.01 ["lot_id"],
1 5 443.16 orderby="id",
)
1 0 0.01 lot_ids_with_quantity = {
1 0 3.12 group["lot_id"][0]: group["quantity"] for group in grouped_quants
}
1 0 0.02 lot_ids_without_qty = self.search(
1 1 731.54 [("id", "not in", list(lot_ids_with_quantity.keys()))]
).ids
1 0 12.49 lot_ids_with_quantity.update({lot_id: 0 for lot_id in lot_ids_without_qty})
res_ids = [
1 0 0.01 lot_id
1 0 46.98 for lot_id, quantity in lot_ids_with_quantity.items()
if OPERATORS[operator](quantity, value)
]
1 0 0.01 return [("id", "in", res_ids)]
Total:
1 13 1269.75
2022-09-30 08:27:33,292 1 INFO zhinst_lab odoo.tools.profiler:
calls queries ms
stock.production.lot --------------------- /odoo/external-src/stock-logistics-workflow/stock_lot_product_qty_search/models/stock_production_lot.py, 17
1 0 0.02 @profile
def _search_product_qty(self, operator, value):
1 0 0.01 if operator not in ("<", ">", "=", "!=", "<=", ">="):
raise UserError(_("Invalid domain operator %s", operator))
1 0 0.01 if not isinstance(value, (float, int)):
raise UserError(_("Invalid domain right operand %s", value))
1 0 0.01 locations_domain = OR(
[
1 0 0.01 [("usage", "=", "internal")],
1 0 0.06 [("usage", "=", "transit"), ("company_id", "!=", False)],
]
)
1 1 3.71 quants_locations = self.env["stock.location"].search(locations_domain)
1 0 0.03 grouped_quants = self.env["stock.quant"].read_group(
1 0 0.05 [("lot_id", "!=", False), ("location_id", "in", quants_locations.ids)],
1 0 0.01 ["lot_id", "quantity"],
1 0 0.01 ["lot_id"],
1 1 441.99 orderby="id",
)
1 0 0.01 lot_ids_with_quantity = {
1 0 3.21 group["lot_id"][0]: group["quantity"] for group in grouped_quants
}
1 0 0.03 lot_ids_without_qty = self.search(
1 1 515.72 [("id", "not in", list(lot_ids_with_quantity.keys()))]
).ids
1 0 12.53 lot_ids_with_quantity.update({lot_id: 0 for lot_id in lot_ids_without_qty})
res_ids = [
1 0 0.01 lot_id
1 0 48.57 for lot_id, quantity in lot_ids_with_quantity.items()
if OPERATORS[operator](quantity, value)
]
1 0 0.01 return [("id", "in", res_ids)]
Total:
1 3 1026.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment