-
-
Notifications
You must be signed in to change notification settings - Fork 592
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
ensure slug history prefers the record that most recently used the slug #663
Conversation
Looks like new test fails on Travis CI. They are passing locally for me. 😞 |
… is not and we are looking for a single unique record
6 similar comments
ok. build is happy now. not sure why coverage dropped (even by the factional percentage) since I only changed an existing line and added a spec for that change. |
@norman any thoughts on this? |
Ensure slug history prefers the record that most recently used the slug
Makes perfect sense - thanks for your work on this. |
Thinking about this some more, it seems like a bug that a record can claim a deleted slug from another record's slug history, that's not intentional behavior at all. Once a slug is used by a record, no other record should be able to use it ever, unless it's deleted from this history. |
I have to disagree. Slug history is generally an SEO optimization. You only fall back to history when no records are actively using it. Staking claim on a name forever, simply by using it once, seems very narrowly focused. If another record decides to actively use a slug that only exists in history, it should be able to do so, I would think. |
I think either design choice is certainly valid, they are different use cases. To reuse a slug you could force people to intentionally delete it from the history. That has good and bad parts. My sense of alarm comes from the fact that the details of how this works have slipped by me for quite some time now. Although I'm generally not in favor of adding more configuration options, perhaps this would be a reasonable place to introduce one in 5.2.0 (the version I'm intending to release this PR in). Or, if not a configuration option, then a method that could be overridden, and better documentation on how this feature is actually working. |
This does seem like a reasonable place to provide a configuration option, something like "allow_slug_reuse"; wouldn't add much in terms of complexity. |
This is now out in 5.2.0.beta.1. No timetable for stable release yet, but probably within a couple weeks. I'm still thinking about the discussion here and haven't taken action yet, but I'll likely include a configuration option in 5.2.0. |
@norman Is this feature available in 5.2.0.beta.1? I tried using it but it gave the same usual results. I was also finding a way to reuse old slugs. I also don't see the change suggested in the 5.0-stable branch where it was merged. |
@norman Hello, is there any news about |
Slugs can be reused by different model instances when the slug is reassigned directly, as in
model_instance.slug = "value_already_in_history"
. This means you can have more than one instance of the slug value for the same type in the history.Currently, in this scenario, the first model instance to use the slug value will win out in a history search, because the
slug_table_record
method relies on natural sorting (by id) and selects the first record.It seems more logical to retrieve the model instance that most recently used the slug value, which would actually be the last record with the slug value in the slug history table.
This PR sets an explicit descending order by created_at on the history table search, so that the selected model is the last one to use the target slug value.