Refactoring update_all_app_data_for_agent code.