We were experiencing long page loads when looking at Harbormaster builds (as in ~10 seconds in some cases). When I used the DarkConsole to view the queries, I could see some of the queries were taking several seconds when executing:
SELECT * FROM `harbormaster_buildartifact` WHERE (buildTargetPHID IN ('PHID-HMBT-74ihxry2sq3pikmjeu3u')) ORDER BY `id` DESC
We have 210221 build artifacts in our system as of writing, so this query was taking several seconds. I added an index on this table (I executed this through the console rather than patching Phabricator's storage definition of HarbormasterBuildArtifact to avoid more merge conflicts):
create index buildartifact_targetphid ON harbormaster_buildartifact (buildTargetPHID);
Once I added this index, the query dropped down to ~480us.
It looks like HEAD doesn't have an index on the buildTargetPHID column; this should be added because of the significant performance benefit when you have a lot of build artifacts in the system.