Fix a problem with an SQL that coule be too large

When getting content-ids for last-modified-date computation
the SQL query could sometimes be to long for Oracle database.
This fix limits the length to the latest contents if the maximum
number is exceeded.
Fixes another long-SQL problem
fixup! Fix a problem with an SQL that coule be too large
Adds debug-logging check to some expressions