public function Basic::trackItemsInserted in Search API 8
Inserts new items into the tracking system for this index.
Parameters
string[] $ids: The item IDs of the new search items.
Overrides TrackerInterface::trackItemsInserted
File
- src/
Plugin/ search_api/ tracker/ Basic.php, line 211
Class
- Basic
- Provides a tracker implementation which uses a FIFO-like processing order.
Namespace
Drupal\search_api\Plugin\search_api\trackerCode
public function trackItemsInserted(array $ids) {
try {
$index_id = $this
->getIndex()
->id();
// Process the IDs in chunks so we don't create an overly large INSERT
// statement.
foreach (array_chunk($ids, 1000) as $ids_chunk) {
// We have to make sure we don't try to insert duplicate items.
$select = $this
->createSelectStatement()
->fields('sai', [
'item_id',
]);
$select
->condition('item_id', $ids_chunk, 'IN');
$existing = $select
->execute()
->fetchCol();
$existing = array_flip($existing);
$insert = $this
->createInsertStatement();
foreach ($ids_chunk as $item_id) {
if (isset($existing[$item_id])) {
continue;
}
list($datasource_id) = Utility::splitCombinedId($item_id);
$insert
->values([
'index_id' => $index_id,
'datasource' => $datasource_id,
'item_id' => $item_id,
'changed' => $this
->getTimeService()
->getRequestTime(),
'status' => $this::STATUS_NOT_INDEXED,
]);
}
if ($insert
->count()) {
$insert
->execute();
}
}
} catch (\Exception $e) {
$this
->logException($e);
}
}