Fix decorator ordering on mysql

MySQL timestamp accuracy is only up to 1 second, so ordering by pkey is
required to return the latest record.

Refactored: Extract shared code from Topic and PrivateTopic