optimize performance of api.php