[TASK] Reduce SQL queries of page tree in workspaces

Nodes of the page tree are highlighted, if that particular node
has versioned elements in the current workspace. However, this is
determined by iterating over all tables and all records for each
page. If having installed many extensions with many tables any
many records, this will produce a lot of SQL queries.

The process of "does have versions" can be stopped once the first
version for a page/node has been found.

Resolves: #50349
Releases: 6.2
Change-Id: Ibaef07bdab87147c6826af8578870c52803dfe03