Filter on g_msgids in Python instead of sending huge list to MySQL

Closes #T53