Trying to optimise code in the hope of fixing issue with long query.

There was a long query, with many id's. Using array_unique to prevent double id's