Skip to content

Commit

Permalink
FIX Update solr reindex to use config value, Update SolrReindexTask t…
Browse files Browse the repository at this point in the history
…o be more effecient (dont iterate subclasses during $type update)
  • Loading branch information
Jake Bentvelzen committed Oct 26, 2016
1 parent 98598f9 commit 25c4563
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
7 changes: 5 additions & 2 deletions code/tasks/SolrReindexJob.php
Expand Up @@ -10,7 +10,7 @@
if (class_exists('AbstractQueuedJob')) {
class SolrReindexJob extends AbstractQueuedJob {

static $at_a_time = 100;
private static $at_a_time = 100;

public function __construct($type = null) {
if (!$type && isset($_GET['type'])) {
Expand Down Expand Up @@ -41,7 +41,10 @@ public function process() {
}

$class = $this->reindexType;
$pages = $class::get()->filter('ID:GreaterThan', $this->lastIndexedID)->sort('ID ASC')->limit('0, ' . self::$at_a_time);
$pages = $class::get();
$pages = $pages->filter(array('ID:GreaterThan' => $this->lastIndexedID));
$pages = $pages->limit(Config::inst()->get(__CLASS__, 'at_a_time'));
$pages = $pages->sort('ID ASC');

if (ClassInfo::exists('Subsite')) {
Subsite::$disable_subsite_filter = false;
Expand Down
23 changes: 16 additions & 7 deletions code/tasks/SolrReindexTask.php
Expand Up @@ -51,17 +51,20 @@ public function run($request) {
$job = new SolrReindexJob($type);
$svc = singleton('QueuedJobService');
$svc->queueJob($job);
echo "<p>Reindexing job for $type has been queued</p>";
$this->log("Reindexing job for $type has been queued");
} else {

$mode = Versioned::get_reading_mode();
Versioned::reading_stage('Stage');

// get the holders first, see if we have any that AREN'T in the root (ie we've already partitioned everything...)
$pages = DataObject::get($type);
$pages = $type::get();
$pages = $pages->filter(array('ClassName' => $type));

/* @var $search SolrSearchService */

$this->log("------------------------------");
$this->log("Start reindexing job for $type (Count: ".$pages->count()."):");
$this->log("------------------------------");
foreach ($pages as $page) {

// Make sure the current page is not orphaned.
Expand All @@ -82,14 +85,14 @@ public function run($request) {
$live = Versioned::get_one_by_stage($page->ClassName, 'Live', "\"$baseTable\".\"ID\" = $page->ID");
if ($live) {
$search->index($live, 'Live');
echo "<p>Reindexed Live version of $live->Title</p>\n";
$this->log("Reindexed Live version of $live->Title");
}

echo "<p>Reindexed (#$page->ID) $page->Title</p>\n";
$this->log("Reindexed (#$page->ID) $page->Title");
$count ++;
} else {
$search->index($page);
echo "<p>Reindexed $type ID#$page->ID</p>\n";
$this->log("Reindexed $type ID#$page->ID");
$count ++;
}
}
Expand All @@ -98,6 +101,12 @@ public function run($request) {
}
}

echo "Reindex complete, $count objects re-indexed<br/>";
$this->log("------------------------------");
$this->log("Reindex complete, $count objects re-indexed");
$this->log("------------------------------");
}

protected function log($message) {
DB::alteration_message($message);
}
}

0 comments on commit 25c4563

Please sign in to comment.