SQL improvements. New parameter for a maximum amount of comments per thread

There is a new configuration parameter:

$a->config['system']['max_comments'] = ...

It configures how much comments should be visible in per post. When you are using the facebook connector you can import posts with several thousands of comments. This kills the memory :)

This parameter limits the comments to the last X comments. Per standard it is set to 1,000. On my own machine i set it to 100.

Additionally I found some more "limit" statements where they don't belong.

And finally I found some statements that were always in my slow query log. Now they aren't anymore :)