Lucas Werkmeister (WMDE) has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/349949 )
Change subject: Cache constraints for property
......................................................................
Cache constraints for property
Avoid querying the database repeatedly for constraints of the same
property by introducing a caching ConstraintLookup.
(To be clear: this only caches the information that e.g. the property
“sibling” should be symmetric, not any individual check results.)
Bug: T89349
Change-Id: Icd42c22b17e9dc5628f59793bb13473fb5a60504
---
A includes/ConstraintCache.php
M includes/ConstraintReportFactory.php
2 files changed, 46 insertions(+), 1 deletion(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
refs/changes/49/349949/1
diff --git a/includes/ConstraintCache.php b/includes/ConstraintCache.php
new file mode 100644
index 0000000..bdf74c2
--- /dev/null
+++ b/includes/ConstraintCache.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace WikibaseQuality\ConstraintReport;
+
+use Wikibase\DataModel\Entity\PropertyId;
+
+/**
+ * A ConstraintLookup that caches the results of another lookup.
+ *
+ * @author Lucas Werkmeister
+ * @license GNU GPL v2+
+ */
+class ConstraintCache implements ConstraintLookup {
+
+ /**
+ * @var ConstraintLookup
+ */
+ private $lookup;
+
+ /**
+ * @var Constraint[][]
+ */
+ private $cache;
+
+ /**
+ * @var ConstraintLookup $lookup The lookup to which all queries are
delegated.
+ */
+ public function __construct( ConstraintLookup $lookup ) {
+ $this->lookup = $lookup;
+ }
+
+ /**
+ * @param PropertyId $propertyId
+ *
+ * @return Constraint[]
+ */
+ public function queryConstraintsForProperty( PropertyId $propertyId ) {
+ $id = $propertyId->getSerialization();
+ if ( !array_key_exists( $id, $this->cache ) ) {
+ $this->cache[$id] =
$this->lookup->queryConstraintsForProperty( $propertyId );
+ }
+ return $this->cache[$id];
+ }
+
+}
diff --git a/includes/ConstraintReportFactory.php
b/includes/ConstraintReportFactory.php
index d63d968..bae8938 100644
--- a/includes/ConstraintReportFactory.php
+++ b/includes/ConstraintReportFactory.php
@@ -107,7 +107,7 @@
$this->delegatingConstraintChecker = new
DelegatingConstraintChecker(
$this->lookup,
$this->getConstraintCheckerMap(),
- new ConstraintRepository()
+ new ConstraintCache(
$this->getConstraintRepository() )
);
}
--
To view, visit https://gerrit.wikimedia.org/r/349949
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icd42c22b17e9dc5628f59793bb13473fb5a60504
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits