Take klass and realm into account when querying posts by  external_ids to optimize postgres queries