mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-01-10 14:10:46 +00:00
Merge pull request #5420 from pixelfed/staging
Update StatusTagsPipeline, fix hashtag bug and formatting
This commit is contained in:
commit
ca7a23daa8
1 changed files with 104 additions and 69 deletions
|
@ -2,27 +2,28 @@
|
|||
|
||||
namespace App\Jobs\StatusPipeline;
|
||||
|
||||
use App\Hashtag;
|
||||
use App\Jobs\MentionPipeline\MentionPipeline;
|
||||
use App\Mention;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\CustomEmojiService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\TrendingHashtagService;
|
||||
use App\StatusHashtag;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\CustomEmojiService;
|
||||
use App\Services\StatusService;
|
||||
use App\Jobs\MentionPipeline\MentionPipeline;
|
||||
use App\Mention;
|
||||
use App\Hashtag;
|
||||
use App\StatusHashtag;
|
||||
use App\Services\TrendingHashtagService;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StatusTagsPipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $activity;
|
||||
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
|
@ -77,28 +78,62 @@ class StatusTagsPipeline implements ShouldQueue
|
|||
}
|
||||
|
||||
if (config('database.default') === 'pgsql') {
|
||||
$hashtag = Hashtag::where('name', 'ilike', $name)
|
||||
->orWhere('slug', 'ilike', str_slug($name, '-', false))
|
||||
$hashtag = DB::transaction(function () use ($name) {
|
||||
$baseSlug = str_slug($name, '-', false);
|
||||
$slug = $baseSlug;
|
||||
$counter = 1;
|
||||
|
||||
$existing = Hashtag::where('name', $name)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
if(!$hashtag) {
|
||||
$hashtag = Hashtag::updateOrCreate([
|
||||
'slug' => str_slug($name, '-', false),
|
||||
'name' => $name
|
||||
]);
|
||||
if ($existing) {
|
||||
if ($existing->slug !== $slug) {
|
||||
while (Hashtag::where('slug', $slug)
|
||||
->where('name', '!=', $name)
|
||||
->exists()) {
|
||||
$slug = $baseSlug.'-'.$counter++;
|
||||
}
|
||||
} else {
|
||||
$hashtag = Hashtag::updateOrCreate([
|
||||
'slug' => str_slug($name, '-', false),
|
||||
'name' => $name
|
||||
$existing->slug = $slug;
|
||||
$existing->save();
|
||||
}
|
||||
|
||||
return $existing;
|
||||
}
|
||||
|
||||
while (Hashtag::where('slug', $slug)->exists()) {
|
||||
$slug = $baseSlug.'-'.$counter++;
|
||||
}
|
||||
|
||||
return Hashtag::create([
|
||||
'name' => $name,
|
||||
'slug' => $slug,
|
||||
]);
|
||||
});
|
||||
} else {
|
||||
$hashtag = DB::transaction(function () use ($name) {
|
||||
$baseSlug = str_slug($name, '-', false);
|
||||
$slug = $baseSlug;
|
||||
$counter = 1;
|
||||
|
||||
while (Hashtag::where('slug', $slug)
|
||||
->where('name', '!=', $name)
|
||||
->exists()) {
|
||||
$slug = $baseSlug.'-'.$counter++;
|
||||
}
|
||||
|
||||
return Hashtag::updateOrCreate(
|
||||
['name' => $name],
|
||||
['slug' => $slug]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
StatusHashtag::firstOrCreate([
|
||||
'status_id' => $status->id,
|
||||
'hashtag_id' => $hashtag->id,
|
||||
'profile_id' => $status->profile_id,
|
||||
'status_visibility' => $status->scope
|
||||
'status_visibility' => $status->scope,
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue