Optimize page permission checking

Hi,

I discovered a bottleneck on my website. Generating the menu can take up to 50 seconds! After this fix, I can go down to 5 seconds. It's still not acceptable, but this is a quick fix.