mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
Optimize SQL queries when searching a rule
Searching all rules then filtering in python the parent path is more efficient than finding all the parent locations and finding the matching rules.
This commit is contained in:
committed by
Sébastien Alix
parent
4ae12c21ce
commit
c837adc236
@@ -82,7 +82,14 @@ class StockReserveRule(models.Model):
|
||||
raise ValidationError(msg)
|
||||
|
||||
def _rules_for_location(self, location):
|
||||
return self.search([("location_id", "parent_of", location.id)])
|
||||
# We'll typically have a handful of rules, so reading all of them then
|
||||
# checking if they are a parent location of the location is pretty
|
||||
# fast. Searching all the parent locations then the rules matching them
|
||||
# can be much slower if we have many locations.
|
||||
rules = self.search([]).filtered(
|
||||
lambda rule: rule.location_id.parent_path.startswith(location.parent_path)
|
||||
)
|
||||
return rules
|
||||
|
||||
def _eval_rule_domain(self, move, domain):
|
||||
move_domain = [("id", "=", move.id)]
|
||||
|
||||
Reference in New Issue
Block a user