Skip to content

Commit 51501fe

Browse files
improve: add clarifying comments to database index update process
Added comments to clarify the two-step process of removing old tokens and bulk inserting new ones. While this is two queries, it's still efficient as the insert is done in bulk rather than individual inserts.
1 parent 6975c73 commit 51501fe

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/Traits/HasEncryptedSearchIndex.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ public function updateSearchIndex(): void
125125
if ($useElastic) {
126126
$this->syncToElasticsearch($rows);
127127
} else {
128+
// Remove existing tokens for this model before inserting new ones
128129
SearchIndex::where('model_type', static::class)
129130
->where('model_id', $this->getKey())
130131
->delete();
131132

133+
// Bulk insert all new tokens in a single query
132134
SearchIndex::insert($rows);
133135
}
134136
}

0 commit comments

Comments
 (0)