Think it might be better/faster to let the DB do some of this sort work? At least get you features and issues ordered by sort_num separately. I think the extra query is worth doing less sorting python side. I guess we'd have to benchmark, but I think it'd be quicker and it's what the DB is good at.