-
-
Notifications
You must be signed in to change notification settings - Fork 588
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
friendly_id - Isolating the slugs to a separate table #558
Comments
+1 |
Sorry, not going to do this. This was how FriendlyId 3.x and below worked. If you have very large tables, performance is significantly worse with the slug in a separate table. |
What if you need one path for everything? |
No, that's for FriendlyId 3.0 and less, from 2+ years ago. There's always an in-table slug now. |
Is there anyway to use the friendly_id_slugs table instead of the in table column? We can't create the slug column in an existing table, but we can create additional tables (friendly_id_slugs), since this table is being used when the history module is used, I doubt the performance is going to be any worse. |
No, at the moment you need to use the in-table slug. The performance of
|
@norman: if the slugs are always in-table, why does |
Because if you want to use the (popular) history module, you need the table. It's a common usage pattern for somebody to set up FriendlyId, not use the history module right away, and then decide to use it on a model, some time after the initial setup. If they created the table as per the instructions, everything works as expected. If they did not, it often ends up leading to a ticket asking "Why doesn't history work." If you find it annoying to have an extra table around that you're not using, then you can just drop the table and/or delete the migration - just remember you'll need to add it back if at some point you want to use the history feature. |
By the way, there is a special flag in generator to skip this migration: https://git.io/vzO6x. May be it's good idea just clarify how to use it in documentation or README? |
@kimrgrey Sure, I think it would be fine to mention that in the docs. I would not put it in the README though; it's a minor detail and the README should be very focused on the absolute basics you need to do to get the library running. There's zero practical impact on an application from having an empty table in its schema, but there is a very practical impact from NOT having it there when you want to use it six months after you last read about how to set up FriendlyId and don't remember that it came with a migration that you skipped. So I don't think its worth mentioning prominently. |
@norman: thanks for the clarifications... if they could make their way to the README, along with how to use the History module that'd be great. Right now the usage docs are pretty hard to find (managed to find http://norman.github.io/friendly_id/FriendlyId/History.html but that was not easy, and it's very miminal). |
@Silex, well, friendly_id has detailed documentation for all features here: http://norman.github.io/friendly_id/file.Guide.html. And this page is referenced on top of the README. |
@kimrgrey: doh... somehow I managed to miss it 😭 Thanks |
I'd still add just a note, maybe with (*) to the README, about the migration+History module. |
@norman Is it still recommended to use the in-table slug? I'm just curious has there been any progress in improving the performance of an external slugs table? If not would recommend that an app not use this gem if it has a use case for Slug only table that referred to it's polymorphic type cc @parndt
|
Hi @copasetickid thanks for the question. It has not been an area of focus, so unless you're inclined to tackle it 😁 😅 the recommendation hasn't changed. |
Thanks, @parndt for clarifying. 😄 Is there value in working on if I ever change my mind or in your experience you found that a separate table is not a good design choice for most use cases? |
You’ll never be able to make the performance of an external slug rival that
of an in-table slug because with an external slug you’ll always either have
to do a join or two queries, which is inherently more expensive than not
doing a join, or doing only one query. Early versions of the library used
only external slugs and it nuked the performance of larger sites.
--
Sent from my phone
|
Thanks for sharing that @norman. I appreciate the insight on this and why its designed this way. 😄 |
Is there any possibility to have slug field in the common/separate table perhaps with Polymorphic association?
Because we are having large database, So I can not create slug field in all the tables. So I want it to be in separate table with polymorphic association like history add on.
For example I have three models User, Product and Slug but the slug field is not present in users and products table. The slug field is present in slugs table.
User Model
Product Model:
Slug Model
I want to find the User record using slug content for example
User.find("rafiu") - to fetch the user with slug content of "rafiu"
It should find the user by joining slugs table.
Is there a way to do this?
I already created post in stackoverflow - http://stackoverflow.com/questions/23866305/friendly-id-isolating-the-slugs-to-a-separate-table
The text was updated successfully, but these errors were encountered: