LucyTurtle
LucyTurtle

Reputation: 1133

Algolia + Laravel -- Do not update index at a specific instance of save()

I am using Laravel Scout + Algolia. We have reached our usage limit because every time someone visits a content page on our site I update the entry in the database to increment the page views counter. This then triggers Algolia to update, even though the page_views variable isn't even stored in Algolia. I am wondering if there is a way to update the database entry without triggering the Algolia update.

Upvotes: 1

Views: 712

Answers (1)

mdexp
mdexp

Reputation: 3567

In the documentation there's a paragraph about that here.
Basically you can run a closure without syncing to Algolia in this way:

$currentInstance = 'your-model'; // This is the variable you want to inject
App\YourModel::withoutSyncingToSearch(function () use ($currentInstance) {
    // Do the increment, and algolia indexing will not be updated
});

Upvotes: 2

Related Questions