[ticket/11599] Only call database sync when required

PHPBB3-11599