Fix regression where wrong set of message identifiers was used
in sql query that was supposed to fetch list of messages from cache