Skip to content

Commit

Permalink
Declare afterCommit in the ModelObserver and add config option and co…
Browse files Browse the repository at this point in the history
…nstructor
  • Loading branch information
bakerkretzmar committed Dec 31, 2020
1 parent ece6758 commit 172eab9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config/scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@

'queue' => env('SCOUT_QUEUE', false),

/*
|--------------------------------------------------------------------------
| Database Transactions
|--------------------------------------------------------------------------
|
| This option allows you to control if the operations that sync your
| data with your search engines are only executed afterall open
| database transactions have committed.
|
*/

'after_commit' => false,

/*
|--------------------------------------------------------------------------
| Chunk Sizes
Expand Down
17 changes: 17 additions & 0 deletions src/ModelObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,30 @@

class ModelObserver
{
/**
* Only dispatch the observer's events after all database transactions have committed.
*
* @var bool
*/
public $afterCommit;

/**
* The class names that syncing is disabled for.
*
* @var array
*/
protected static $syncingDisabledFor = [];

/**
* Create a new observer instance.
*
* @return void
*/
public function __construct()
{
$this->afterCommit = config('scout.after_commit', false);
}

/**
* Enable syncing for the given class.
*
Expand Down

0 comments on commit 172eab9

Please sign in to comment.