#336358 by Wesley Tanaka, brianV: fix slow query in ping module and correct its use of the database API