-
Notifications
You must be signed in to change notification settings - Fork 86
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
Fix scopeTransOrderBy duplicates #586
Conversation
@aurelien-roy what do you think about this proposed change? |
I think that this would be a solution to both problems.
should be changed to:
Then join method should look like this:
|
@mterman can you update your PR to do this? |
@mjauvin I updated the PR. |
Hi! Just wanted to say that I hit this problem (and 587), I applied this pull request and everything works like a charm. When do you think that you will publish it? Thank you! |
@mariavilaro I need people to test this and also stats to show before/after perfs. Also need a better naming for this. |
The test worked for me. I can't help you with the performance stats because my databases are small. What do you mean with the better naming? |
@mariavilaro you can't provide details like number of records for the Rainlab.Translate tables and the time it takes for the queries before and after applying this PR? |
@mterman @aurelien-roy can you guys also provide for performance metrics before/after this PR is applied? |
@mariavilaro what are you saying, that the PR makes no difference? |
@acasar whenever we're evaluating changes for performance sake they must be validated to not change existing behaviour in any breaking way, and we also need benchmarks to prove that the change actually improves performance. |
I tested this and there is no fallback as I expected. I almost exclusively use the transWhere() scope in situation where I want to find a model based on a slug (which is usually provided in a cms page :slug param) and as long as the slug has a translation, this new transWhereSpecificLocale() scope will do the job, but as soon as a slug only exists in the default language, that breaks if the page is opened in one of the other languages with that slug in the default language. In summary, if 'en' is the default locale and 'fr' is an alternate locale:
Personally, this is of no use to me as you would require another query to get the fallback record. What am I missing? |
Yes, that is correct.
You are not missing anything. That is the expected behaviour of the transWhereSpecificLocale scope. For me that is useful, we usually don't fallback to the default locale it some content is not available in selected locale. As per your example, if there are no records in FR locale we will not show content in EN locale but go to 404 or redirect to homepage. |
Maybe, instead of adding a new scope "transWhereSpecificLocale", we could just add a new param $fallbackToDefaultLocale (default true,so we don't introduce a breaking change) to transWhere to say if we want to fallback to the default locale or not: Classic transWhere with fallback: New transWhere without fallback that can use the new code: I think that other laravel translation libraries do it like this. |
This PR is an alternative version of rainlab#586 Instead of creating a separate method that has a different behavior to the original implementation, I managed to fix ``transWhere`` itself by utilizing 2 queries instead of the slow orWhere clause. This implementation also preserves the fallback functionality. I made some tests on my project (originally discussed here: rainlab#581) - now I have 2 queries that execute in ~ 5 ms instead of a single 60 second query. The improvement is significant. Comments are welcome.
To preserve the original fallback behavior I made an alternative suggestion here: #623 |
@mterman would you mind updating this to keep the scopeTransOrderBy() changes, remove the changes to scopeTransWhere() and drop scopeTransWhereSpecificLocale? Thanks. |
@mjauvin are you planning on merging both? |
@LukeTowers yes, but this one only for the transOrderBy changes. |
@mterman if you could make the requested changes, I'd like to merge this for upcoming 1.7.4. I'd like to make the release today or tomorrow. Thanks. |
scopeTransWhere reverted, scopeTransWhereSpecificLocale removed
Thanks @mterman, can you pull changes from master in your branch? Tests have been fixed in latest master. @aurelien-roy can you retest this to make sure it works as expected? Thanks guys! |
@mterman please pull latest changes for the upstream master branch before merging, looks like you didn't. |
@mjauvin Is this the correct upsteram url? And have I been merging from the right branch?
|
@mterman I'm sorry, looks like this is good on your end... not sure why those tests are going through fine when using your branch locally, though... I'll find the problem and get back to you. How long until you're offline? |
Ok, I made a change to your repo to fix this, we're good now. |
Added scope TransWhereSpecificLocale that uses where clause on only specified locale and not default locale and selected locale. I think that this is a more common use case for the transWhere and it is much faster.
This addresses the issue: #581
Also in this pull request, I added checking for multiple joins to the translation index table. With these changes, it is now possible to chain multiple transWhere clauses, also with multiple transWhereSpecificLocale and transOrderBy. It is also possible to mix locales in different clauses.
Please feel free to change name of the TransWhereSpecificLocale to something shorter.