Skip to content

Instantly share code, notes, and snippets.

@mityukov
Created September 12, 2017 09:38
Show Gist options
  • Save mityukov/8474efca4c06ef25570cd4e97f8b5dac to your computer and use it in GitHub Desktop.
Save mityukov/8474efca4c06ef25570cd4e97f8b5dac to your computer and use it in GitHub Desktop.
class ActivityRepositoryEloquent extends BaseRepository implements ActivityRepository
{
// ...
public function insertMany($records)
{
$searchFields = [
'subdomain',
'element_type',
'element_id',
'slug',
];
foreach ($records as $record) {
$record['deleted'] = false;
$this->model->updateOrCreate(
array_only($record, $searchFields),
array_except($record, $searchFields)
);
}
}
}
@mityukov
Copy link
Author

Current implementation of something like updateOrCreateMany. But it's very slow even with compound index, consisting of all $searchFields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment