Try this:
- Split off meta sites (using
linked_meta
status) - Order by ageOrder by age
- Move StackApps to the bottom (as its a special case)
- Re-insert meta sites below their linked site (as determined by address)
Of course, you should cache this aggressively. In particular, the site age can be cached indefinitely which will save you #(site) requests on each recalc.