1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12:41 +01:00
phorge-phorge/resources/sql/autopatches/20191028.uriindex.01.rebuild.php

7 lines
116 B
PHP
Raw Normal View History

In the repository URI index, store Phabricator's own URIs as tokens Summary: Fixes T13435. If you move Phabricator or copy data from one environment to another, the repository URI index currently still references the old URI, since it writes the URI as a plain string. This may make "arc which" and similar workflows have difficulty identifying repositories. Instead, store the "phabricator.base-uri" domain and the "diffusion.ssh-host" domain as tokens, so lookups continue to work correctly even after these values change. Test Plan: - Added unit tests to cover the normalization. - Ran migration, ran daemons, inspected `repository_uriindex` table, saw a mixture of sensible tokens (for local domains) and static domains (like "github.com"). - Ran this thing: ``` $ echo '{"remoteURIs": ["ssh://git@local.phacility.com/diffusion/P"]}' | ./bin/conduit call --method repository.query --trace --input - Reading input from stdin... >>> [2] (+0) <conduit> repository.query() >>> [3] (+3) <connect> local_repository <<< [3] (+3) <connect> 555 us >>> [4] (+5) <query> SELECT `r`.* FROM `repository` `r` LEFT JOIN `local_repository`.`repository_uriindex` uri ON r.phid = uri.repositoryPHID WHERE (uri.repositoryURI IN ('<base-uri>/diffusion/P')) GROUP BY `r`.phid ORDER BY `r`.`id` DESC LIMIT 101 <<< [4] (+5) <query> 596 us <<< [2] (+6) <conduit> 6,108 us { "result": [ { "id": "1", "name": "Phabricator", "phid": "PHID-REPO-2psrynlauicce7d3q7g2", "callsign": "P", "monogram": "rP", "vcs": "git", "uri": "http://local.phacility.com/source/phabricator/", "remoteURI": "https://github.com/phacility/phabricator.git", "description": "asdf", "isActive": true, "isHosted": false, "isImporting": false, "encoding": "UTF-8", "staging": { "supported": true, "prefix": "phabricator", "uri": null } } ] } ``` Note the `WHERE` clause in the query normalizes the URI into "<base-uri>", and the lookup succeeds. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13435 Differential Revision: https://secure.phabricator.com/D20872
2019-10-28 22:22:07 +01:00
<?php
// @phase worker
In the repository URI index, store Phabricator's own URIs as tokens Summary: Fixes T13435. If you move Phabricator or copy data from one environment to another, the repository URI index currently still references the old URI, since it writes the URI as a plain string. This may make "arc which" and similar workflows have difficulty identifying repositories. Instead, store the "phabricator.base-uri" domain and the "diffusion.ssh-host" domain as tokens, so lookups continue to work correctly even after these values change. Test Plan: - Added unit tests to cover the normalization. - Ran migration, ran daemons, inspected `repository_uriindex` table, saw a mixture of sensible tokens (for local domains) and static domains (like "github.com"). - Ran this thing: ``` $ echo '{"remoteURIs": ["ssh://git@local.phacility.com/diffusion/P"]}' | ./bin/conduit call --method repository.query --trace --input - Reading input from stdin... >>> [2] (+0) <conduit> repository.query() >>> [3] (+3) <connect> local_repository <<< [3] (+3) <connect> 555 us >>> [4] (+5) <query> SELECT `r`.* FROM `repository` `r` LEFT JOIN `local_repository`.`repository_uriindex` uri ON r.phid = uri.repositoryPHID WHERE (uri.repositoryURI IN ('<base-uri>/diffusion/P')) GROUP BY `r`.phid ORDER BY `r`.`id` DESC LIMIT 101 <<< [4] (+5) <query> 596 us <<< [2] (+6) <conduit> 6,108 us { "result": [ { "id": "1", "name": "Phabricator", "phid": "PHID-REPO-2psrynlauicce7d3q7g2", "callsign": "P", "monogram": "rP", "vcs": "git", "uri": "http://local.phacility.com/source/phabricator/", "remoteURI": "https://github.com/phacility/phabricator.git", "description": "asdf", "isActive": true, "isHosted": false, "isImporting": false, "encoding": "UTF-8", "staging": { "supported": true, "prefix": "phabricator", "uri": null } } ] } ``` Note the `WHERE` clause in the query normalizes the URI into "<base-uri>", and the lookup succeeds. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13435 Differential Revision: https://secure.phabricator.com/D20872
2019-10-28 22:22:07 +01:00
PhabricatorRebuildIndexesWorker::rebuildObjectsWithQuery(
'PhabricatorRepositoryQuery');