GrafiteInc / CMS

Decoupled CMS for any Laravel app, gain control of: pages, blogs, galleries, events, images, custom modules and more.
https://cms.grafite.ca
MIT License
494 stars 104 forks source link

Performance improvement in case of translation #111

Closed Nowi5 closed 6 years ago

Nowi5 commented 6 years ago

Hi all,

in case there are more than one language possible, you should improve the different repositories to load directly the translations and reduce the amount of SQL statements. For example in the PageRepository you can improve the "published" function by enhancing "->with('translation')"

Further you should improve the check if translation is needed. This is very complex:

@if (config('app.locale') !== config('quarx.default-language'))
                    @if ($page->translation(config('app.locale')))

                    <td><a href="{!! url(Config::get('app.locale_prefix').'/'.$page->translation(config('app.locale'))->data->url) !!}">{!! $page->translation(config('app.locale'))->data->title !!}</a></td>
                    @else
                        <td><a href="{!! url(Config::get('app.locale_prefix').'/'.$page->url) !!}">{{ $page->title }}</a></td>
                    @endif
                @else
                    <td><a href="{!! url(Config::get('app.locale_prefix').'/'.$page->url) !!}">{{ $page->title }}</a></td>
                @endif

The page attributes should be taken automatically if the config has 'auto-translate' => true.

What do you think about that?

mlantz commented 6 years ago

Hey @Nowi5 I agree that was complicated, I ended up adding a method to the base model called ->asObject() in this case it will load the page as its translated object or its default based on the request, however that doesn't address your first point about the with addition. I'll review that given that I have made changes which impact that