Couldn't be this subscription retrieval simplified? This will generate sql query for each pool.