Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f19bbc7
Implemented pausing mechanisms into cli/finder_indexer.php.
frankmayer Jan 6, 2017
caff45f
Merge branch 'staging' into cli-finder-indexer
rdeutz May 27, 2017
df969b9
Merge branch 'staging' into cli-finder-indexer
frankmayer Jun 1, 2017
8c1cee8
Additional changes according to reviewer's comments
frankmayer Jun 1, 2017
4f2731e
Merge remote-tracking branch 'origin/cli-finder-indexer' into cli-fin…
frankmayer Jun 1, 2017
a1ef7e1
Merge branch 'staging' into cli-finder-indexer
frankmayer Jun 10, 2017
3a2fac8
- Correction of typo
frankmayer Jun 10, 2017
7eee4b9
Changes according to reviewer's comments
frankmayer Jun 12, 2017
61d80e7
Merge branch 'staging' into cli-finder-indexer
frankmayer Sep 1, 2017
05b4211
Small corrections
frankmayer Sep 1, 2017
81c3d8a
Merge branch 'staging' into cli-finder-indexer
frankmayer May 17, 2018
b7134e2
Fix deploy version
frankmayer May 17, 2018
2d131b3
Merge branch 'staging' into cli-finder-indexer
frankmayer May 19, 2018
d6a4e1a
Some cosmetic fixes (does not change behavior)
frankmayer May 19, 2018
8d758d4
Merge branch 'staging' into cli-finder-indexer
frankmayer Jul 19, 2019
fd107eb
Made some changes according to @SharkyKZ 's notes
frankmayer Jul 20, 2019
b9aa03f
- Enriched and adjusted documentation of script
frankmayer Jul 20, 2019
d996fc2
Optimized pausing section for the case of `--pause=0`. Don't need to …
frankmayer Jul 20, 2019
9bb48d6
- Better implementation of default behavior and associated settings.
frankmayer Jul 20, 2019
b8ce1c4
Codestyle
frankmayer Jul 22, 2019
9b4cd19
Merge branch 'staging' into cli-finder-indexer
frankmayer Jul 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 105 additions & 4 deletions cli/finder_indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,30 @@
* This is a command-line script to help with management of Smart Search.
*
* Called with no arguments: php finder_indexer.php
* Performs an incremental update of the index.
* Performs an incremental update of the index using dynamic pausing.
*
* Called with --purge: php finder_indexer.php --purge
* IMPORTANT NOTE: since Joomla version __DEPLOY_VERSION__ the default behavior of this script has changed.
* If called with no arguments, the `--pause` argument is silently applied, in order to avoid the possibility of
* stressing the server too much and making a site (or multiple sites, if on a shared environment) unresponsive.
* If a pause is unwanted, just apply `--pause=0` to the command
*
* Called with --purge php finder_indexer.php --purge
* Purges and rebuilds the index (search filters are preserved).
*
* Called with --pause `php finder_indexer.php --pause`
* or --pause=x or `php finder_indexer.php --pause=x` where x = seconds.
* or --pause=division or `php finder_indexer.php --pause=division` The default divisor is 5.
* If another divisor is required, it can be set with --divisor=y, where
* y is the integer divisor
*
* This will pause for x seconds between batches,
* in order to give the server some time to catch up
* if --pause is called without an assignment, it defaults to dynamic pausing
* using the division method with a divisor of 5
* (eg. 1 second pause for every 5 seconds of batch processing time)
*
* Called with --minproctime=x Will set the minimum processing time of batches for a pause to occur. Defaults to 1
*
*/

// We are a valid entry point.
Expand Down Expand Up @@ -91,6 +111,37 @@ class FinderCli extends JApplicationCli
*/
private $filters = array();

/**
* Pausing type or defined pause time in seconds.
* One pausing type is implemented: 'division' for dynamic calculation of pauses
*
* Defaults to 'division'
*
* @var string|integer
* @since __DEPLOY_VERSION__
*/
private $pause = 'division';

/**
* The divisor of the division: batch-processing time / divisor.
* This is used together with --pause=division in order to pause dynamically
* in relation to the processing time
* Defaults to 5
*
* @var integer
* @since __DEPLOY_VERSION__
*/
private $divisor = 5;

/**
* Minimum processing time in seconds, in order to apply a pause
* Defaults to 1
*
* @var integer
* @since __DEPLOY_VERSION__
*/
private $minimumBatchProcessingTime = 1;

/**
* Entry point for Smart Search CLI script
*
Expand All @@ -114,6 +165,20 @@ public function doExecute()
$_SERVER['HTTP_HOST'] = 'domain.com';
JFactory::getApplication('site');

$this->minimumBatchProcessingTime = $this->input->getInt('minproctime', 1);

// Pause between batches to let the server catch a breath. The default, if not set by the user, is set in the class property `pause`
$pauseArg = $this->input->get('pause', $this->pause, 'raw');

if ($pauseArg === 'division')
{
$this->divisor = $this->input->getInt('divisor', $this->divisor);
}
else
{
$this->pause = (int) $pauseArg;
}

// Purge before indexing if --purge on the command line.
if ($this->input->getString('purge', false))
{
Expand Down Expand Up @@ -207,7 +272,43 @@ private function index()
JEventDispatcher::getInstance()->trigger('onBuildIndex');

// Batch reporting.
$this->out(JText::sprintf('FINDER_CLI_BATCH_COMPLETE', $i + 1, round(microtime(true) - $this->qtime, 3)), true);
$this->out(JText::sprintf('FINDER_CLI_BATCH_COMPLETE', $i + 1, $processingTime = round(microtime(true) - $this->qtime, 3)), true);

if ($this->pause !== 0)
{
// Pausing Section
$skip = !($processingTime >= $this->minimumBatchProcessingTime);
$pause = 0;

if ($this->pause === 'division' && $this->divisor > 0)
{
if (!$skip)
{
$pause = round($processingTime / $this->divisor);
}
else
{
$pause = 1;
}
}
elseif ($this->pause > 0)
{
$pause = $this->pause;
}

if ($pause > 0 && !$skip)
{
$this->out(JText::sprintf('FINDER_CLI_BATCH_PAUSING', $pause), true);
sleep($pause);
$this->out(JText::_('FINDER_CLI_BATCH_CONTINUING'));
}

if ($skip)
{
$this->out(JText::sprintf('FINDER_CLI_SKIPPING_PAUSE_LOW_BATCH_PROCESSING_TIME', $processingTime, $this->minimumBatchProcessingTime), true);
}
// End of Pausing Section
}
}
}
catch (Exception $e)
Expand Down Expand Up @@ -331,7 +432,7 @@ private function getFilters()
$this->out(JText::_('FINDER_CLI_SAVE_FILTERS'));

// Get the taxonomy ids used by the filters.
$db = JFactory::getDbo();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('filter_id, title, data')
Expand Down
3 changes: 3 additions & 0 deletions language/en-GB/en-GB.finder_cli.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

FINDER_CLI="Smart Search INDEXER"
FINDER_CLI_BATCH_COMPLETE=" * Processed batch %s in %s seconds."
FINDER_CLI_BATCH_CONTINUING=" * Continuing processing of batch ..."
FINDER_CLI_BATCH_PAUSING=" * Pausing processing for %s seconds ..."
FINDER_CLI_FILTER_RESTORE_WARNING="Warning: Did not find taxonomy %s/%s in filter %s"
FINDER_CLI_INDEX_PURGE="Clear index"
FINDER_CLI_INDEX_PURGE_FAILED="- index clear failed."
Expand All @@ -17,5 +19,6 @@ FINDER_CLI_SAVE_FILTER_COMPLETED="- number of saved filters: %s"
FINDER_CLI_SAVE_FILTERS="Saving filters"
FINDER_CLI_SETTING_UP_PLUGINS="Setting up Smart Search plugins"
FINDER_CLI_SETUP_ITEMS="Setup %s items in %s seconds."
FINDER_CLI_SKIPPING_PAUSE_LOW_BATCH_PROCESSING_TIME=" * Skipping pause, as previous batch had a very low processing time (%ss < %ss)"
FINDER_CLI_STARTING_INDEXER="Starting Indexer"