'Given a state group try to return a previous group and a delta between
the old and the new.
Returns:
(prev_group, delta_ids), where both may be None.'

@cached(max_entries=10000, iterable=True)
def get_state_group_delta(self, state_group):

    def _get_state_group_delta_txn(txn):
        prev_group = self._simple_select_one_onecol_txn(txn, table='state_group_edges', keyvalues={'state_group': state_group}, retcol='prev_state_group', allow_none=True)
        if (not prev_group):
            return _GetStateGroupDelta(None, None)
        delta_ids = self._simple_select_list_txn(txn, table='state_groups_state', keyvalues={'state_group': state_group}, retcols=('type', 'state_key', 'event_id'))
        return _GetStateGroupDelta(prev_group, {(row['type'], row['state_key']): row['event_id'] for row in delta_ids})
    return self.runInteraction('get_state_group_delta', _get_state_group_delta_txn)
