Skip to content

Commit 5979e43

Browse files
Merge pull request #18 from ginkelsoft-development/fix/optimize-database-index-upsert
improve: add clarifying comments to database index update process
2 parents 1ad9843 + 51501fe commit 5979e43

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
@@ -130,10 +130,12 @@ public function updateSearchIndex(): void
130130
if ($useElastic) {
131131
$this->syncToElasticsearch($rows);
132132
} else {
133+
// Remove existing tokens for this model before inserting new ones
133134
SearchIndex::where('model_type', static::class)
134135
->where('model_id', $this->getKey())
135136
->delete();
136137

138+
// Bulk insert all new tokens in a single query
137139
SearchIndex::insert($rows);
138140
}
139141
}

0 commit comments

Comments
 (0)