This whole process is to backfill missing information to an API my company uses that's built on Sharepoint (of all things) so it's basically a single use function.
I built a command that will function on the scheduler and take small chunks like so:
foreach (Example::query()
->whereIn(
new Expression('(example_id, published_at)'),
Example::query()
->select('example_id')
->selectRaw('MAX(published_at)')
->groupBy('example_id')
->whereDate('published_at', '<', $this->date)
->whereNull('removed_at')
->whereNotNull('example_id')
->where('filled', false)
)
->orderBy('example_id')
->take(50)
->cursor() as $record) {
$data = new ExampleResource($record);
$this->service->backfill([
'numeric_id' => $record->id,
'example_id' => $record->numeric_id,
'data' => json_encode($data),
]);
}
$this->service being the API service class that sends the data down.
It has to be done in small chunks because the amount of data from the ExampleResource is very large.
In the service I get the response back and then update the filled column so it no longer gets selected.
Using your query I dropped from sending 2990 records to only 2145 which is great!
But alas once this process has been completed this code will be removed as the backfill process won't be needed in the future. The worst part, I set the system up to send this data (that's being backfilled now) from the start, but it was rejected ... then 8 months and thousands of records later .... "Oh we need all that data from before."
Aggravating.
Thanks again for your assistance.