Differential D19869 Diff 47447 src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php
| Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | protected function finishParse() { | ||||
| } | } | ||||
| } | } | ||||
| private function writeCommitChanges( | private function writeCommitChanges( | ||||
| PhabricatorRepository $repository, | PhabricatorRepository $repository, | ||||
| PhabricatorRepositoryCommit $commit, | PhabricatorRepositoryCommit $commit, | ||||
| array $changes) { | array $changes) { | ||||
| $conn = $repository->establishConnection('w'); | |||||
| $repository_id = (int)$repository->getID(); | $repository_id = (int)$repository->getID(); | ||||
| $commit_id = (int)$commit->getID(); | $commit_id = (int)$commit->getID(); | ||||
| // NOTE: This SQL is being built manually instead of with qsprintf() | |||||
| // because some SVN changes affect an enormous number of paths (millions) | |||||
| // and this showed up as significantly slow on a profile at some point. | |||||
| $changes_sql = array(); | $changes_sql = array(); | ||||
| foreach ($changes as $change) { | foreach ($changes as $change) { | ||||
| $values = array( | $changes_sql[] = qsprintf( | ||||
| $conn, | |||||
| '(%d, %d, %d, %nd, %nd, %d, %d, %d, %d)', | |||||
| $repository_id, | $repository_id, | ||||
| (int)$change->getPathID(), | (int)$change->getPathID(), | ||||
| $commit_id, | $commit_id, | ||||
| nonempty((int)$change->getTargetPathID(), 'null'), | nonempty((int)$change->getTargetPathID(), null), | ||||
| nonempty((int)$change->getTargetCommitID(), 'null'), | nonempty((int)$change->getTargetCommitID(), null), | ||||
| (int)$change->getChangeType(), | (int)$change->getChangeType(), | ||||
| (int)$change->getFileType(), | (int)$change->getFileType(), | ||||
| (int)$change->getIsDirect(), | (int)$change->getIsDirect(), | ||||
| (int)$change->getCommitSequence(), | (int)$change->getCommitSequence()); | ||||
| ); | |||||
| $changes_sql[] = '('.implode(', ', $values).')'; | |||||
| } | } | ||||
| $conn_w = $repository->establishConnection('w'); | |||||
| queryfx( | queryfx( | ||||
| $conn_w, | $conn, | ||||
| 'DELETE FROM %T WHERE commitID = %d', | 'DELETE FROM %T WHERE commitID = %d', | ||||
| PhabricatorRepository::TABLE_PATHCHANGE, | PhabricatorRepository::TABLE_PATHCHANGE, | ||||
| $commit_id); | $commit_id); | ||||
| foreach (PhabricatorLiskDAO::chunkSQL($changes_sql) as $chunk) { | foreach (PhabricatorLiskDAO::chunkSQL($changes_sql) as $chunk) { | ||||
| queryfx( | queryfx( | ||||
| $conn_w, | $conn, | ||||
| 'INSERT INTO %T | 'INSERT INTO %T | ||||
| (repositoryID, pathID, commitID, targetPathID, targetCommitID, | (repositoryID, pathID, commitID, targetPathID, targetCommitID, | ||||
| changeType, fileType, isDirect, commitSequence) | changeType, fileType, isDirect, commitSequence) | ||||
| VALUES %LQ', | VALUES %LQ', | ||||
| PhabricatorRepository::TABLE_PATHCHANGE, | PhabricatorRepository::TABLE_PATHCHANGE, | ||||
| $chunk); | $chunk); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||