| Conditions | 11 |
| Paths | 40 |
| Total Lines | 87 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types = 1); |
||
| 29 | public function bulkIndex($indexName, $dirty = false, $climate = null) |
||
| 30 | { |
||
| 31 | $indexes = new Indexes(); |
||
| 32 | $index = $indexes->getIndex($indexName); |
||
| 33 | |||
| 34 | /** @var string $clazz */ |
||
| 35 | $clazz = $index->getClass(); |
||
| 36 | |||
| 37 | |||
| 38 | $startTime = \microtime(true); |
||
| 39 | |||
| 40 | if (!(is_null($climate))) { |
||
| 41 | $climate->border('*'); |
||
| 42 | $climate->green()->bold('Indexing sitetree'); |
||
| 43 | $climate->border(); |
||
| 44 | } |
||
| 45 | |||
| 46 | $filters = ['ShowInSearch' => true]; |
||
| 47 | if ($dirty) { |
||
| 48 | $filters['IsDirtyFreeTextSearch'] = true; |
||
| 49 | } |
||
| 50 | |||
| 51 | $nDocuments = SiteTree::get()->filter($filters)->count(); |
||
| 52 | |||
| 53 | error_log('N DOCUMENTS: ' . $nDocuments); |
||
| 54 | |||
| 55 | if ($nDocuments > 0) { |
||
| 56 | $config = SiteConfig::current_site_config(); |
||
| 57 | |||
| 58 | // * @phpstan-ignore-next-line |
||
| 59 | $bulkSize = $config->BulkSize; |
||
| 60 | $pages = 1+\round($nDocuments / $bulkSize); |
||
| 61 | $progress = !is_null($climate) ? $climate->progress()->total($nDocuments) : null; |
||
| 62 | |||
| 63 | if (!is_null($climate)) { |
||
| 64 | $climate->green('Pages: ' . $pages); |
||
| 65 | $climate->green()->info('Indexing ' . $nDocuments .' objects'); |
||
| 66 | } |
||
| 67 | |||
| 68 | $factory = new BulkIndexerFactory(); |
||
| 69 | $bulkIndexer = $factory->getBulkIndexer(); |
||
| 70 | $bulkIndexer->setIndex($indexName); |
||
| 71 | |||
| 72 | for ($i = 0; $i < $pages; $i++) { |
||
| 73 | $dataObjects = $clazz::get()->limit($bulkSize, $i*$bulkSize)->filter($filters); |
||
| 74 | foreach ($dataObjects as $do) { |
||
| 75 | // Note this adds data to the payload, does not actually indexing against the third party search engine |
||
| 76 | $bulkIndexer->addDataObject($do); |
||
| 77 | } |
||
| 78 | |||
| 79 | // index objects up to configured bulk size |
||
| 80 | $bulkIndexer->indexDataObjects(); |
||
| 81 | $current = $bulkSize * ($i+1); |
||
| 82 | if ($current > $nDocuments) { |
||
| 83 | $current = $nDocuments; |
||
| 84 | } |
||
| 85 | if (!is_null($progress)) { |
||
| 86 | $progress->current($current); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | |||
| 92 | $endTime = \microtime(true); |
||
| 93 | $delta = $endTime-$startTime; |
||
| 94 | |||
| 95 | $rate = \round($nDocuments / $delta, 2); |
||
| 96 | |||
| 97 | $elapsedStr = \round($delta, 2); |
||
| 98 | |||
| 99 | if (!is_null($climate)) { |
||
| 100 | $climate->bold()->blue()->inline("{$nDocuments}"); |
||
| 101 | $climate->blue()->inline(' objects indexed in '); |
||
| 102 | $climate->bold()->blue()->inline("{$elapsedStr}"); |
||
| 103 | $climate->blue()->inline('s, '); |
||
| 104 | $climate->bold()->blue()->inline("{$rate}"); |
||
| 105 | $climate->blue(' per second '); |
||
| 106 | } |
||
| 107 | |||
| 108 | $clazz = $index->getClass(); |
||
| 109 | $table = Config::inst()->get($clazz, 'table_name'); |
||
| 110 | |||
| 111 | |||
| 112 | DB::query("UPDATE \"{$table}\" SET \"IsDirtyFreeTextSearch\" = 0"); |
||
| 113 | |||
| 114 | // @todo How to get the table name from versions? |
||
| 115 | DB::query("UPDATE \"{$table}_Live\" SET \"IsDirtyFreeTextSearch\" = 0"); |
||
| 116 | |||
| 120 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths