Latest api code fix too many db connections