Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

[RTM] Always fix the domain and language when generating URLs #8238

Merged
merged 13 commits into from
Feb 29, 2016

Conversation

leofeyer
Copy link
Member

This PR fixed #8204 and all duplicate tickets for good (hopefully).

@leofeyer leofeyer self-assigned this Feb 26, 2016
@leofeyer leofeyer added this to the 3.5.7 milestone Feb 26, 2016
@aschempp
Copy link
Member

Why do we need still the $strForceLang?

@aschempp
Copy link
Member

Also, can we add support for $arrRow being a PageModel?

@leofeyer
Copy link
Member Author

Thought about it, too. Maybe not in the bugfix release.

@aschempp
Copy link
Member

What's the difference? If we always force domain, we always force the language…

@leofeyer
Copy link
Member Author

Why do we need still the $strForceLang?

We do not need it, we just keep supporting it for BC. Not sure what people have used it for …

@Toflar
Copy link
Member

Toflar commented Feb 26, 2016

Not sure what people have used it for …

To force the language, like the parameter says? If you don't have any front end context, how would you generate it correctly? :-)

BTW: I think I have a better approach for your code performance wise which will be fully backwards compatible:

  • Check if tl_page.language has changed in save_callback and if so, update all child records with it.
  • Modify the PageModel and introduce a getLanguage() method:
public function getLanguage()
{
    // Ensure root page language is inherited if not set by save_callback (BC)
    if ('' === $this->language) {
        $this->loadDetails();
    }

    return $this->language;
}
  • Support passing the \PageModel to \Controller::generateFrontendUrl() then instead of using $arrRow['language'] use \PageModel::getLanguage().

Why in 3.5: Well, we have to change the handling because it's buggy at the moment but if we already change it then we should make it right :-)

@leofeyer
Copy link
Member Author

To force the language, like the parameter says? If you don't have any front end context, how would you generate it correctly? :-)

No front end context is required. It will set the language and domain based on $page->rootLanguage and $page->domain, which are both set in PageModel::loadDetails().

I think I have a better approach for your code performance wise which will be fully backwards compatible

How is your code performing better? We'd still have to bubble up to the root page to check the domain, wouldn't we?

@leofeyer
Copy link
Member Author

Not to forget $page->trail, which also required to load the page details.

@leofeyer
Copy link
Member Author

The PR is ready to merge now. Please review one last time.

@leofeyer leofeyer changed the title [WIP] Always fix the domain and language when generating URLs [RTM] Always fix the domain and language when generating URLs Feb 28, 2016
$objDatabase = \Database::getInstance();

// Get published pages
$objPages = $objDatabase->prepare("SELECT * FROM tl_page WHERE pid=? AND (start='' OR start<='$time') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1' ORDER BY sorting")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, we intentionally do not use models here because of performance and memory …

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember anything alike. Has there been a ticket?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember something like this as well. Cannot find it though but it sure is an issue with a lot of pages. Please do not change this!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to change it to fix the initial problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail miserably, I tell you. This is a no go, I'm sorry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are telling me this based on something you think you remember, which however is nowhere documented?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leofeyer
Copy link
Member Author

I have investigated a bit. Here are some findings of where not to use models:

Rebuilding the search index is not one of them. Also, I have debugged rebuilding the search index with and without models:

With models

with-models

Without models

without-models

Using models requires 10% more memory, however, it also decreases the number of database queries and the number of rows which need to be transferred.

@Toflar What exactly are your concerns?

@Toflar
Copy link
Member

Toflar commented Feb 29, 2016

Try this on an installation with 3000 pages that are split over 12 domains times 4 languages (= 48 root pages). I think it's going to fail 😄

@leofeyer
Copy link
Member Author

I found the ticket about what you think to remember: #7928

We have also discussed that we need to use the database class again, but then we found a bug in the Model class, which turned out to cause the problems.

After fixing the bug, the memory issues were gone. So we can safely merge this PR now.

@aschempp
Copy link
Member

After fixing the bug, the memory issues were gone.

That's just not true. The last comment was "please test", so we don't know if anything changes. The major difference (in my opinion) is that the models will be kept in the registry indefinitely, whereas the database result will be removed from memory when not used anymore.

@leofeyer
Copy link
Member Author

Of course they were gone. We have tested the change extensively, we have just not commented in the ticket. But it was only closed two weeks after finding the bug.

@Toflar
Copy link
Member

Toflar commented Feb 29, 2016

I tried to do some tests to back my use case and ended up with a regular page model requiring more or less 20kb of RAM. So for 3000 pages it would require about 60 MB RAM which is fine then I think :-) If they are split over 48 root pages it will certainly need quite a lot more memory but it should still be fine. So I guess my concerns are refuted :-)

However, I still think, inheriting dns, language and whatever other columns are needed to generate a front end url, is the way to go. You can safely generate a front end url from one single database row without having to load the model and its root page and bubble up all the pages to load the details then. It would greatly improve performance, memory consumption and developer experience :-)

@aschempp
Copy link
Member

However, I still think, inheriting dns, language and whatever other columns are needed to generate a front end url, is the way to go. You can safely generate a front end url from one single database row without having to load the model and its root page and bubble up all the pages to load the details then. It would greatly improve performance, memory consumption and developer experience :-)

That's certainly something we should think about, but certainly not in the 3.5.7 patch release ^^

@leofeyer
Copy link
Member Author

However, I still think, inheriting dns, language and whatever other columns are needed to generate a front end url, is the way to go.

Yes, I'm totally with you on this one. However, that is a different issue.

The problem is that storing the fields in the database is pretty cumbersome and also error-prone, because you have to keep it in sync when the root page changes. There are some solutions for this problem already and backbone87 has implemented one in #6193 (his initial issue was #6830).

@leofeyer
Copy link
Member Author

So now that we have settled this and that I have changed all you have suggested, can I merge the PR?

@Toflar
Copy link
Member

Toflar commented Feb 29, 2016

Imho, yes.

@leofeyer
Copy link
Member Author

Ah, no, I cannot. I have not solved this issue brought up by @aschempp :(

@leofeyer
Copy link
Member Author

You could have added a flag to $arrOptions to disable the fePreview check?

I have thought about exactly this, too 😄

I have not asked you though, because I also think it is a new feature. But we should definitely implement this!

@leofeyer
Copy link
Member Author

I have created a separate ticket: contao/core-bundle#452

@leofeyer leofeyer merged commit a83463a into hotfix/3.5.7 Feb 29, 2016
@leofeyer leofeyer deleted the hotfix/fix-frontend-urls branch February 29, 2016 16:17
@leofeyer
Copy link
Member Author

Merged in c68d813.

jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Mar 5, 2016
### 4.1.1 (2015-03-03)

 * Remove the "disable IP check" field from the back end settings (see #436).
 * Do not quote the search string in `FIND_IN_SET()` (see #424).
 * Always fix the domain and language when generating URLs (see contao/core#8238).
 * Fix two issues with the flexible back end theme (see contao/core#8227).
 * Correctly toggle custom page type icons (see contao/core#8236).
 * Correctly render the links in the monthly/yearly event list menu (see contao/core#8140).
 * Skip the registration related fields if a user is duplicated (see contao/core#8185).
 * Correctly show the form field type help text (see contao/core#8200).
 * Correctly create the initial version of a record (see contao/core#8141).
 * Correctly show the "expand preview" buttons (see contao/core#8146).
 * Correctly check that a password does not match the username (see contao/core#8209).
 * Check if a directory exists before executing `mkdir()` (see contao/core#8150).
 * Do not link to the maintenance module if the user cannot access it (see contao/core#8151).
 * Show the "new folder" button in the template manager (see contao/core#8138).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants