Currently, we query the constraints table for the constraints on a property every time we check constraints for a property. If an entity has multiple statements with the same property, or if an API request checks several entities at once, this can results in several identical, redundant requests. To optimize constraint checking, we should only query the constraints once per property.
|Resolved||Lucas_Werkmeister_WMDE||T173695 Enable constraint checks by default for users|
|Open||None||T103228 Improve performance of constraint check|
|Resolved||Lucas_Werkmeister_WMDE||T89349 [Task] Only query constraints table once per property|
It’s still valid, but I think there are two fairly separate tasks here.
- We currently query the database for constraints on a property every time we check constraints on a property, which can be several times per request if there are several statements of the same property on an item, or if an API request includes several items. (This currently happens in DelegatingConstraintChecker::checkStatement and ConstraintRepository::queryConstraintsForProperty.) I imagine we could introduce some caching ConstraintLookup.
- Some constraints, like “has type” (type) or “has statement” (item), are really constraints on the item, not on the statement; if multiple statements all introduce the same constraint on the item (for example, parent, sibling, date of birth, etc. might all require type: human), it only needs to be checked once. This seems like a more fundamental change to me, and unrelated to the first task, which is purely technical.