Merge 3.1.0 into stable.
Don't return message_stats if it's empty; similar to what the old DB did (if it is empty it will get JSONised as [] not {}).
merge default into bug25543
merge bug25543 into default