Wrap rebuild_depth_cache! in a transaction