I was browsing through some other code and noticed this:
First, the comment says "Requires Extension:Echo". It actually requires [[mw:Extension:Thanks]], which in turn requires Echo.
It then has a class_exists( 'MWEchoDbFactory' ) call. This tells you if Echo is installed, not if Thanks is installed. class_exists( 'ApiThank' ) will probably work.
Then comes "MWEchoDbFactory::getDB( DB_SLAVE )". Echo has been written to be used with multiple backends. Even though DB is currently the only supported ones, that should not be depended upon (gerrit change 92248 is an attempt to add a Redis backend).
Echo doesn't really support grouping by category, this is probably something that should be done in the Thanks extension (storing the last Thank).
That said, according to bug 49087 comment 4, "Thanks are intended to be ephemeral" so I'm not sure trying to look for the last one, regardless of how old it is, is a good idea.