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
} }
} }
$hashtag = Hashtag::firstOrCreate([ if(config('database.default') === 'pgsql') {
'slug' => str_slug($name) $hashtag = Hashtag::where('name', 'ilike', $name)
], [ ->orWhere('slug', 'ilike', str_slug($name))
'name' => $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([ StatusHashtag::firstOrCreate([
'status_id' => $status->id, 'status_id' => $status->id,