Next up -- another Laravel Scout lesson learned at scale:
If you enable queuing in Scout, your models are indexed by queued jobs that are dispatched when calling `$model->save()`
In busy apps, two things might occur:
- the same model may be saved several times in a short window of time, or;
- the scout queue might be backed up and your worker is working through them
Either way, you'll end up with lots of duplicate jobs attempting to index the same model(s) before the worker has ever reached them in the queue to process
This leads to lots of unnecessary churn, since the latest model instance is retrieved from the database when it’s worked on the queue, so every duplicate job ends up re-fetching and re-indexing the same final state of the model anyway
To resolve this, I submitted a PR (which was merged) to include two jobs that can be opted-into which implement the ShouldBeUniqueUntilProcessing interface which prevents queuing jobs for model(s) that are already waiting in the queue to be indexed