Page MenuHomePhorge

phabricator_feed.feed_storydata.transactionPHIDs: reduce storage space
Open, Needs TriagePublic

Description

In the database phabricator_feed and table feed_storydata column storyData you may find something like this:

{"objectPHID":"PHID-TASK-pvbycc3zpcxyfpnpov2q","transactionPHIDs":{"PHID-XACT-TASK-ua2746zfceyom4x":"PHID-XACT-TASK-ua2746zfceyom4x"}}

Beautified a bit:

{
 "objectPHID":"PHID-TASK-pvbycc3zpcxyfpnpov2q",
 "transactionPHIDs":{
  "PHID-XACT-TASK-ua2746zfceyom4x":"PHID-XACT-TASK-ua2746zfceyom4x"
}}

Description of the Problem

As you can see, transactionPHIDs may contain the same value, as both the key and the value.

This is reasonable at the level of business logic, but not very reasonable in the data structure, as it only wastes space unnecessarily.

Proposed Solution

Probably the data structure should change from this map:

{"objectPHID":"PHID-TASK-pvbycc3zpcxyfpnpov2q","transactionPHIDs":{"PHID-XACT-TASK-ua2746zfceyom4x":"PHID-XACT-TASK-ua2746zfceyom4x"}}

To this array:

{"objectPHID":"PHID-TASK-pvbycc3zpcxyfpnpov2q","transactionPHIDs":["PHID-XACT-TASK-ua2746zfceyom4x"]}

Note, probably it should not change to this, since the key is generally ignored:

{"objectPHID":"PHID-TASK-pvbycc3zpcxyfpnpov2q","transactionPHIDs":{"PHID-XACT-TASK-ua2746zfceyom4x":"1"}}

Proposed Implementation

This seems a reasonable change that seems to have backward compatibility:

diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
index d5fd81a65b..86bae52e10 100644
--- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
+++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
@@ -4162,7 +4162,7 @@ abstract class PhabricatorApplicationTransactionEditor
 
     return array(
       'objectPHID'        => $object->getPHID(),
-      'transactionPHIDs'  => mpull($xactions, 'getPHID'),
+      'transactionPHIDs'  => array_values(mpull($xactions, 'getPHID')),
     );
   }

To apply that, we probably need a very long maintenance script