-
-
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
Avoid double unique check in rails and friendly_id #967
Comments
Bump! I'm seeing the same issue in my app. Noticed when my queries count skyrocketed.
Is there a way to remove the additional query? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Same here, I'm getting 4 of them when it looks like it should only be 2 or probably only 1: SELECT 1 AS one FROM "deals" INNER JOIN "friendly_id_slugs" ON "friendly_id_slugs"."sluggable_type" = $1 AND "friendly_id_slugs"."sluggable_id" = "deals"."id" WHERE "deals"."id" IS NOT NULL AND "deals"."slug" = $2 LIMIT $3
SELECT 1 AS one FROM "deals" INNER JOIN "friendly_id_slugs" ON "friendly_id_slugs"."sluggable_type" = $1 AND "friendly_id_slugs"."sluggable_id" = "deals"."id" WHERE "deals"."id" IS NOT NULL AND "friendly_id_slugs"."sluggable_type" = 'Deal' AND "friendly_id_slugs"."slug" = 'rustic-bronze-computer' LIMIT $2
SELECT 1 AS one FROM "deals" INNER JOIN "friendly_id_slugs" ON "friendly_id_slugs"."sluggable_type" = $1 AND "friendly_id_slugs"."sluggable_id" = "deals"."id" WHERE "deals"."id" IS NOT NULL AND "deals"."slug" = $2 LIMIT $3
SELECT 1 AS one FROM "deals" INNER JOIN "friendly_id_slugs" ON "friendly_id_slugs"."sluggable_type" = $1 AND "friendly_id_slugs"."sluggable_id" = "deals"."id" WHERE "deals"."id" IS NOT NULL AND "friendly_id_slugs"."sluggable_type" = 'Deal' AND "friendly_id_slugs"."slug" = 'rustic-bronze-computer' LIMIT $2 |
I use friendly_id to generate slug i my rails 6 application.
I realized that the check for a unique name is done twice for each record addition.
If I delete:
it only executes once.
It looks like the check is also done on add, not as it would seem on update.
How do I prevent the name from being checked for uniqueness twice?
The text was updated successfully, but these errors were encountered: