Page MenuHomePhabricator

D9234.diff
No OneTemporary

D9234.diff

diff --git a/resources/sql/autopatches/20140521.factlint.1.sql b/resources/sql/autopatches/20140521.factlint.1.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20140521.factlint.1.sql
@@ -0,0 +1,4 @@
+ALTER TABLE {$NAMESPACE}_fact.fact_aggregate
+ ADD COLUMN `stringAHash` VARCHAR(64) COLLATE utf8_bin NOT NULL,
+ DROP KEY `factType`,
+ ADD UNIQUE KEY factType (`factType`, `objectPHID`, `stringAHash`);
diff --git a/src/applications/fact/daemon/PhabricatorFactDaemon.php b/src/applications/fact/daemon/PhabricatorFactDaemon.php
--- a/src/applications/fact/daemon/PhabricatorFactDaemon.php
+++ b/src/applications/fact/daemon/PhabricatorFactDaemon.php
@@ -204,18 +204,19 @@
foreach ($facts as $fact) {
$sql[] = qsprintf(
$conn,
- '(%s, %s, %s, %d)',
+ '(%s, %s, %s, %s, %d)',
$fact->getFactType(),
$fact->getObjectPHID(),
$fact->getStringA(),
+ md5($fact->getStringA()),
$fact->getValueX());
}
foreach (array_chunk($sql, 256) as $chunk) {
queryfx(
$conn,
- 'INSERT INTO %T (factType, objectPHID, stringA, valueX) VALUES %Q
- ON DUPLICATE KEY UPDATE valueX = VALUES(valueX)',
+ 'INSERT INTO %T (factType, objectPHID, stringA, stringAHash, valueX)
+ VALUES %Q ON DUPLICATE KEY UPDATE valueX = VALUES(valueX)',
$table_name,
implode(', ', $chunk));
}
diff --git a/src/applications/fact/storage/PhabricatorFactAggregate.php b/src/applications/fact/storage/PhabricatorFactAggregate.php
--- a/src/applications/fact/storage/PhabricatorFactAggregate.php
+++ b/src/applications/fact/storage/PhabricatorFactAggregate.php
@@ -5,6 +5,7 @@
protected $factType;
protected $objectPHID;
protected $stringA;
+ protected $stringAHash;
protected $valueX;
public function getConfiguration() {
@@ -23,4 +24,14 @@
) + parent::getConfiguration();
}
+ /*
+ * Ensure that the hash in the database gets updated. We
+ * can't use the full length stringA field as part of the
+ * unique key because the maximum unique key is 787 bytes.
+ */
+ public function setStringA($value) {
+ $this->setStringAHash(md5($value));
+ return parent::setStringA($value);
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
May 26 2024, 10:07 PM (5 w, 13 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6294052
Default Alt Text
D9234.diff (2 KB)

Event Timeline