Skip to content

Commit

Permalink
Update audit node command for D10 (#595)
Browse files Browse the repository at this point in the history
* Update audit node command for D10

* Make batch size smaller as ElasticSearch going away

* Fix lint errors
  • Loading branch information
anthony-malkoun authored Feb 24, 2025
1 parent faea2d7 commit 772e409
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions modules/tide_search/src/Commands/TideSearchCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,23 @@
class TideSearchCommands extends DrushCommands {

/**
* Audit nodeids that needs to be published/indexed based on search index.
* Audits node ids that needs to be published/indexed based on search index.
*
* @usage drush tide-search-audit-nodes
* Update the domains on the site taxonomy based on an environment variable.
* The list of items not in the search index can be added using the following
* command where '--id-list' is the output from running
* 'tide:search-audit-nodes'
*
* 'drush search-api:index-sample --datasource=entity:node --id-list=123,456'
*
* @param string $indexId
* The name of the Search API index to audit, e.g. 'node'.
*
* @return string
* A comma delimited list of ids that can be passed to
* 'drush search_api:index-sample'
*
* @usage drush tide-search-audit-nodes node
* Audit 'node' index for missing items
*
* @command tide:search-audit-nodes
* @aliases tide-san,tide-search-audit-nodes
Expand Down Expand Up @@ -91,14 +104,14 @@ public static function getNidsFromSearchIndex($indexId) {
throw new ConsoleException(t('@index was not found'));
}
$total = $indexes[$indexId]->getTrackerInstance()->getTotalItemsCount();
$no_of_batches = ceil($total / 1000);
// If the result set is more than 1000 then run it in batch.
$no_of_batches = ceil($total / 500);
// If the result set is more than 500 then run it in batch.
if ($no_of_batches > 1) {
$nid_starting_point = 0;
for ($i = 1; $i <= $no_of_batches; $i++) {
try {
$query = $indexes[$indexId]->query();
$query->range(0, 1000);
$query->range(0, 500);
$query->sort('nid');
$query->addCondition('nid', $nid_starting_point, '>');
$results = $query->execute();
Expand Down Expand Up @@ -146,6 +159,7 @@ public static function getPublishedNodeIds() {
->condition('type', 'alert', '!=')
->condition('status', 1)
->sort('nid')
->accessCheck(FALSE)
->condition('nid', $pointer, '>')
->range(0, 100)
->execute();
Expand Down

0 comments on commit 772e409

Please sign in to comment.