Skip to content
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

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

Tofandel
Copy link
Contributor

@Tofandel Tofandel commented Nov 20, 2024

A few things this PR tackle:

  1. 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

  2. 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

  3. 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


$this->assertCount(2, $model->slugs()->get());
$this->assertEquals('slug-update-2', $model->getSlug());
}

public function testReactivateSlug(): void
Copy link
Contributor Author

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

@ifox
Copy link
Member

ifox commented Nov 20, 2024

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.

@Tofandel
Copy link
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


if (!empty(Arr::join($slugData, '-'))) {
$object->twillSlugData[] = [
'slug' => Str::slug(Arr::join($slugData, '-')),
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All module slugs get reset on reorder.
2 participants