Update StatusTagsPipeline, deduplicate hashtags on postgres

This commit is contained in:
Daniel Supernault 2023-05-02 23:31:16 -06:00
parent 055aa6b39f
commit 867cbc757c
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -71,11 +71,24 @@ class StatusTagsPipeline implements ShouldQueue
}
}
if(config('database.default') === 'pgsql') {
$hashtag = Hashtag::where('name', 'ilike', $name)
->orWhere('slug', 'ilike', str_slug($name))
->first();
if(!$hashtag) {
$hashtag = new Hashtag;
$hashtag->name = $name;
$hashtag->slug = str_slug($name);
$hashtag->save();
}
} else {
$hashtag = Hashtag::firstOrCreate([
'slug' => str_slug($name)
], [
'name' => $name
]);
}
StatusHashtag::firstOrCreate([
'status_id' => $status->id,