Optimisation of the coupling of ion strings to an optical cavity