Review end to end the slug saving flow#2696
Open
Tofandel wants to merge 6 commits into
Open
Conversation
Tofandel
commented
Nov 20, 2024
| $this->assertEquals('slug-update-2', $model->getSlug()); | ||
| } | ||
|
|
||
| public function testReactivateSlug(): void |
Contributor
Author
There was a problem hiding this comment.
This test was removed because it entirely duplicated the testSlugLooping
Member
|
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. |
Contributor
Author
|
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 |
Tofandel
commented
Nov 20, 2024
|
|
||
| if (!empty(Arr::join($slugData, '-'))) { | ||
| $object->twillSlugData[] = [ | ||
| 'slug' => Str::slug(Arr::join($slugData, '-')), |
Contributor
Author
There was a problem hiding this comment.
This is the part of the code that does concatenation on slugAttributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
getSingleSlugParamsThere 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
The new
$slugFieldsgoes a long way in the path to fully support #860 (right now it will correctly generate it from all the fields in the backend but not yet the browser side)