Open 0bserver opened 6 years ago
Do you know the performance of LIKE
?
The solution to this problem is simple: do not clear realurl data. tx_ttnews[tt_news]=the-news-title-as-path-segment
will only happen in one case: you removed data that realurl requires to decode URLs correctly. So you get consequences for your own actions.
Most likely I will not integrate this solution because performance of LIKE
is terrible and this will lower realurl decoding speed. Sorry.
I'm aware that ''LIKE'' has a perfomance hit. However this is not something that happens on every page load – only if no cache entry can be found. In my example it only happens if somebody opens the SINGLE view before somebody opens the LIST view (because in the latter case the UrlEncoder for all the links to the SINGLE views will run first – correct me if I'm wrong).
Since, as you say, you don't normally clear realurl data, this ''LIKE'' solution will not be in use most of the time. But if you happen to debug a live website and you clear realurl data for any reason, you don't have control over which pages the visitors will open first; will it be LIST or SINGLE? Will they navigate the main menu or will they follow a link to a news from Facebook?
And that's where we need a safety net.
Problem:
We have tt_news entries with the error
no news_id given
in SINGLE view. Debugging shows that TYPO3 requeststx_ttnews[tt_news]=the-news-title-as-path-segment
instead oftx_ttnews[tt_news]=123
. That happens whenUrlDecoder->convertAliasToId()
tries a reverse lookup from the tablett_news.title
and fails. Because of thatUrlDecoder->decodeUrlParameterBlockUseAsIs()
is executed and creates the aforementioned dysfunctionalGETvar
with the path segement instead of an id.Further down the line a cache entry is created where the-news-title-as-path-segment points to a url containing
tx_ttnews[tt_news]=the-news-title-as-path-segment
(created when the SINGLE view is loaded), but other cache entries with the-news-title-as-path-segment can exist pointing to a url withtx_ttnews[tt_news]=123
(created when the LIST view is loaded). In that case RealURL will choose the first entry it finds and considers valid, but that can be the one with the dysfunctionalGETvar
.Solution:
Back to
UrlDecoder->convertAliasToId()
: We can in fact use a better lookup from the table.$value
is split by-
and a WHERE clause is created of the formalias_field LIKE '%the%%news%%title%%as%%path%%segment%'
.That takes care of all the commas, hyphens, and other characters that might be in
alias_field
. Our problem has been solved by that.While we are much more likely to find a database row this way we might run into false positives when the regular expression fits more than one entry. In that case we can assume that the shortest hit is the right one.
I have created a pull request to take care of the issue. #614