@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Count and report skipped documents from "bin/search index"

Summary:
Ref T12450. There's currently a bad behavior where inserting a document into one search service marks it as up to date everywhere.

This isn't nearly as obvious as it should be because `bin/search index` doesn't make it terribly clear when a document was skipped because the index version was already up to date.

When running `bin/seach index` without `--force` or `--background`, keep track of updated vs not-updated documents and print out some guidance. In other configurations, try to provide more help too.

Test Plan: {F4452134}

Reviewers: chad, 20after4

Reviewed By: 20after4

Maniphest Tasks: T12450

Differential Revision: https://secure.phabricator.com/D17597

+76 -2
+76 -2
src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php
··· 87 87 } 88 88 89 89 if (!$is_background) { 90 - $console->writeOut( 91 - "%s\n", 90 + echo tsprintf( 91 + "**<bg:blue> %s </bg>** %s\n", 92 + pht('NOTE'), 92 93 pht( 93 94 'Run this workflow with "%s" to queue tasks for the daemon workers.', 94 95 '--background')); ··· 109 110 ); 110 111 111 112 $any_success = false; 113 + 114 + // If we aren't using "--background" or "--force", track how many objects 115 + // we're skipping so we can print this information for the user and give 116 + // them a hint that they might want to use "--force". 117 + $track_skips = (!$is_background && !$is_force); 118 + 119 + $count_updated = 0; 120 + $count_skipped = 0; 121 + 112 122 foreach ($phids as $phid) { 113 123 try { 124 + if ($track_skips) { 125 + $old_versions = $this->loadIndexVersions($phid); 126 + } 127 + 114 128 PhabricatorSearchWorker::queueDocumentForIndexing($phid, $parameters); 129 + 130 + if ($track_skips) { 131 + $new_versions = $this->loadIndexVersions($phid); 132 + if ($old_versions !== $new_versions) { 133 + $count_updated++; 134 + } else { 135 + $count_skipped++; 136 + } 137 + } 138 + 115 139 $any_success = true; 116 140 } catch (Exception $ex) { 117 141 phlog($ex); ··· 127 151 pht('Failed to rebuild search index for any documents.')); 128 152 } 129 153 154 + if ($track_skips) { 155 + if ($count_updated) { 156 + echo tsprintf( 157 + "**<bg:green> %s </bg>** %s\n", 158 + pht('DONE'), 159 + pht( 160 + 'Updated search indexes for %s document(s).', 161 + new PhutilNumber($count_updated))); 162 + } 163 + 164 + if ($count_skipped) { 165 + echo tsprintf( 166 + "**<bg:yellow> %s </bg>** %s\n", 167 + pht('SKIP'), 168 + pht( 169 + 'Skipped %s documents(s) which have not updated since they were '. 170 + 'last indexed.', 171 + new PhutilNumber($count_skipped))); 172 + echo tsprintf( 173 + "**<bg:blue> %s </bg>** %s\n", 174 + pht('NOTE'), 175 + pht( 176 + 'Use "--force" to force the index to update these documents.')); 177 + } 178 + } else if ($is_background) { 179 + echo tsprintf( 180 + "**<bg:green> %s </bg>** %s\n", 181 + pht('DONE'), 182 + pht( 183 + 'Queued %s document(s) for background indexing.', 184 + new PhutilNumber(count($phids)))); 185 + } else { 186 + echo tsprintf( 187 + "**<bg:green> %s </bg>** %s\n", 188 + pht('DONE'), 189 + pht( 190 + 'Forced search index updates for %s document(s).', 191 + new PhutilNumber(count($phids)))); 192 + } 130 193 } 131 194 132 195 private function loadPHIDsByNames(array $names) { ··· 206 269 return $phids; 207 270 } 208 271 272 + private function loadIndexVersions($phid) { 273 + $table = new PhabricatorSearchIndexVersion(); 274 + $conn = $table->establishConnection('r'); 275 + 276 + return queryfx_all( 277 + $conn, 278 + 'SELECT extensionKey, version FROM %T WHERE objectPHID = %s 279 + ORDER BY extensionKey, version', 280 + $table->getTableName(), 281 + $phid); 282 + } 209 283 210 284 }