-
Notifications
You must be signed in to change notification settings - Fork 577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Review end to end the slug saving flow #2696
base: 3.x
Are you sure you want to change the base?
Conversation
|
||
$this->assertCount(2, $model->slugs()->get()); | ||
$this->assertEquals('slug-update-2', $model->getSlug()); | ||
} | ||
|
||
public function testReactivateSlug(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was removed because it entirely duplicated the testSlugLooping
Thank you so much for diving into this @Tofandel. We do have a few projects that use multiple slug attributes. This is used in tandem with parent-child modules, so that children of different parents can reuse the same slug without a suffix. So the second attribute we add in that case (and a column in the slugs table) is the parent ID. |
In that case maybe I can instead add a new property for slugAttributes so that we can get the new behavior without a breaking change |
|
||
if (!empty(Arr::join($slugData, '-'))) { | ||
$object->twillSlugData[] = [ | ||
'slug' => Str::slug(Arr::join($slugData, '-')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the part of the code that does concatenation on slugAttributes
A few things this PR tackle:
Performance of saving slugs: we now check if the slug attributes were modified to know if the slug needs to be recomputed, this means no query at all if no slug change. A lot of unnecessary or duplicated queries were also removed. A single slug creation before needed between 10 and 16 queries and now only runs between 3 and 6
Get slugParams was split between 2 functions which for the most part duplicated the logic. It is now all encompassed into the original function, deprecating
getSingleSlugParams
There is a lot of confusion regarding multiple
slugAttributes
[Missing docs] Slugs and slugAttributes #755 as well as in the code, some parts of the code used slugAttributes to generate a concatenated slug, some other parts of the code assume that the first is the slug and the rest is additional columns in the slug table (but the later doesn't make much sense because it would just copy an existing attribute into the slug table, so I do not understand what it achieves).To avoid a breaking change a $slugFields property and $slugDeps property were introduced, if they are not defined, it will fallback to $slugAttributes to determine those
Superseedes #2688
Fixes #2681 #2693